]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Documents/TreeData.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Documents / TreeData.php
1 <?php
2  if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 require_once('include/ytree/Node.php');
39
40
41
42 //function returns an array of objects of Node type.
43 function get_node_data($params,$get_array=false) {
44     $ret=array();
45     $click_level=$params['TREE']['depth'];
46     $subcat_id=$params['NODES'][$click_level]['id'];
47     $cat_id=$params['NODES'][$click_level-1]['id'];
48     $href=true;
49     if (isset($params['TREE']['caller']) and $params['TREE']['caller']=='Documents' ) {
50         $href=false;
51     }
52         $nodes=get_documents($cat_id,$subcat_id,$href);
53         foreach ($nodes as $node) {
54                 $ret['nodes'][]=$node->get_definition();
55         }
56         $json = new JSON(JSON_LOOSE_TYPE);
57         $str=$json->encode($ret);
58         return $str;
59 }
60
61 /*
62  *  
63  *
64  */
65  function get_category_nodes($href_string){
66     $nodes=array();
67     global $mod_strings;
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);
71     $current_cat_id=null;
72     $cat_node=null;
73     while (($row=$GLOBALS['db']->fetchByAssoc($result))!= null) {
74
75         if (empty($row['category_id'])) {
76             $cat_id='null';
77             $cat_name=$mod_strings['LBL_CAT_OR_SUBCAT_UNSPEC'];
78         } else {
79             $cat_id=$row['category_id'];
80             $cat_name=$app_list_strings['document_category_dom'][$row['category_id']];
81         }            
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;
85             
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;
90         } 
91
92         if (empty($row['subcategory_id'])) {
93             $subcat_id='null';
94             $subcat_name=$mod_strings['LBL_CAT_OR_SUBCAT_UNSPEC'];
95         } else {
96             $subcat_id=$row['subcategory_id'];
97             $subcat_name=$app_list_strings['document_subcategory_dom'][$row['subcategory_id']];
98         }            
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;
103         
104         $cat_node->add_node($subcat_node);
105     }    
106     if (!empty($cat_node)) $nodes[]=$cat_node;
107
108     return $nodes;
109  }
110  
111 function get_documents($cat_id, $subcat_id,$href=true) {
112     $nodes=array();
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'";
117     } else {
118         $query.=" and category_id is null";
119     }
120         
121     if ($subcat_id != 'null') {
122         $query.=" and subcategory_id='$subcat_id'";
123     } else {
124         $query.=" and subcategory_id is null";
125     }
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']);
130         if ($href) {
131             $node->set_property("href", $href_string);
132         }
133         $node->expanded = true;
134         $node->dynamic_load = false;
135         
136         $nodes[]=$node;
137     }
138     return $nodes;
139 }
140 ?>