2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 require_once('include/ytree/Node.php');
42 //function returns an array of objects of Node type.
43 function get_node_data($params,$get_array=false) {
45 $click_level=$params['TREE']['depth'];
46 $subcat_id=$params['NODES'][$click_level]['id'];
47 $cat_id=$params['NODES'][$click_level-1]['id'];
49 if (isset($params['TREE']['caller']) and $params['TREE']['caller']=='Documents' ) {
52 $nodes=get_documents($cat_id,$subcat_id,$href);
53 foreach ($nodes as $node) {
54 $ret['nodes'][]=$node->get_definition();
56 $json = new JSON(JSON_LOOSE_TYPE);
57 $str=$json->encode($ret);
65 function get_category_nodes($href_string){
68 global $app_list_strings;
69 $query="select distinct category_id, subcategory_id from documents where deleted=0 order by category_id, subcategory_id";
70 $result=$GLOBALS['db']->query($query);
73 while (($row=$GLOBALS['db']->fetchByAssoc($result))!= null) {
75 if (empty($row['category_id'])) {
77 $cat_name=$mod_strings['LBL_CAT_OR_SUBCAT_UNSPEC'];
79 $cat_id=$row['category_id'];
80 $cat_name=$app_list_strings['document_category_dom'][$row['category_id']];
82 if (empty($current_cat_id) or $current_cat_id != $cat_id) {
83 $current_cat_id = $cat_id;
84 if (!empty($cat_node)) $nodes[]=$cat_node;
86 $cat_node = new Node($cat_id, $cat_name);
87 $cat_node->set_property("href", $href_string);
88 $cat_node->expanded = true;
89 $cat_node->dynamic_load = false;
92 if (empty($row['subcategory_id'])) {
94 $subcat_name=$mod_strings['LBL_CAT_OR_SUBCAT_UNSPEC'];
96 $subcat_id=$row['subcategory_id'];
97 $subcat_name=$app_list_strings['document_subcategory_dom'][$row['subcategory_id']];
99 $subcat_node = new Node($subcat_id, $subcat_name);
100 $subcat_node->set_property("href", $href_string);
101 $subcat_node->expanded = false;
102 $subcat_node->dynamic_load = true;
104 $cat_node->add_node($subcat_node);
106 if (!empty($cat_node)) $nodes[]=$cat_node;
111 function get_documents($cat_id, $subcat_id,$href=true) {
113 $href_string = "javascript:select_document('doctree')";
114 $query="select * from documents where deleted=0";
115 if ($cat_id != 'null') {
116 $query.=" and category_id='$cat_id'";
118 $query.=" and category_id is null";
121 if ($subcat_id != 'null') {
122 $query.=" and subcategory_id='$subcat_id'";
124 $query.=" and subcategory_id is null";
126 $result=$GLOBALS['db']->query($query);
127 $current_cat_id=null;
128 while (($row=$GLOBALS['db']->fetchByAssoc($result))!= null) {
129 $node = new Node($row['id'], $row['document_name']);
131 $node->set_property("href", $href_string);
133 $node->expanded = true;
134 $node->dynamic_load = false;