. */ /** * @brief Script used to populate tree branches * * @file * @author * @date $date$ * @version $Revision$ * @ingroup admin */ if(isset($_REQUEST['branch_id']) && !empty($_REQUEST['branch_id']) && isset($_REQUEST['tree_id']) && !empty($_REQUEST['tree_id'])) { $string = $_REQUEST['branch']; $search="'branch_level_id'"; $search="#branch_level_id\":(.*)\,#U"; preg_match($search,$string,$out); $count=count($out[0]); if($count == 1) { $find = true; } $branch_level_id = str_replace("branch_level_id\":", "", $out[0]); $branch_level_id = str_replace(",", "", $branch_level_id); $branch_level_id = str_replace("\"", "", $branch_level_id); if (file_exists('../../../../../../../core/class/class_functions.php')) { include_once('../../../../../../../core/class/class_functions.php'); } else { include_once('../../../../../core/class/class_functions.php'); } if (file_exists('../../../../../../../core/init.php')) { include_once('../../../../../../../core/init.php'); } else { include_once('../../../../../core/init.php'); } require_once 'core/class/class_functions.php'; require_once 'core/class/class_db.php'; require_once 'core/class/class_core_tools.php'; require_once("apps".DIRECTORY_SEPARATOR."maarch_entreprise".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_contacts_v2.php"); $core_tools = new core_tools(); $core_tools->load_lang(); $core_tools->test_user(); $func = new functions(); $tree_id = $_REQUEST['tree_id']; $db = new dbquery(); $db->connect(); $contactv2 = new contacts_v2(); $where = ""; if($branch_level_id == "1") { $db->query("select contact_id, society, society_short, lastname, firstname, is_corporate_person, enabled from ".$_SESSION['tablename']['contacts_v2']." where contact_type = ".$_REQUEST['branch_id']." order by society, lastname "); $children = array(); while($res = $db->fetch_object()) { $contact = ''; if($res->is_corporate_person == 'Y'){ $contact = ucfirst($func->show_string($res->society, true)); if ($res->society_short <> '') { $contact .= ' ('.$res->society_short.')'; } } else { $contact = strtoupper($func->show_string($res->lastname, true)) . ' ' . $func->show_string($res->firstname, true); if ($res->society <> '') { $contact .= ' ('.$res->society.')'; } } array_push($children, array('id' => $res->contact_id, 'contact_label' => $contact, 'enabled' => $res->enabled)); } if(count($children) > 0) { if (file_exists( $_SESSION['config']['corepath'] . 'custom' . DIRECTORY_SEPARATOR . $_SESSION['custom_override_id'] . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'contacts' . DIRECTORY_SEPARATOR . 'contact_tree' . DIRECTORY_SEPARATOR . 'get_tree_children_contact.php' ) ) { $openlink = '../../custom/' . $_SESSION['custom_override_id'] . '/apps/' . $_SESSION['config']['app_id'] . '/admin/contacts/contact_tree/get_tree_children_contact.php'; } else { $openlink = 'admin/contacts/contact_tree/get_tree_children_contact.php'; } echo "["; for($cpt_level2=0; $cpt_level2< count($children); $cpt_level2++) { $color = ""; if ($children[$cpt_level2]['enabled'] == 'N') { $color = "style=\"color:red;\""; } echo "{'id':'".$children[$cpt_level2]['id']."', 'txt':'".addslashes($children[$cpt_level2]['contact_label'])."', 'onopenpopulate' : funcOpen, 'openlink' : '".$openlink."', 'canhavechildren' : true, 'branch_level_id' : 2}"; if(isset($children[$cpt_level2+1]['id']) && !empty($children[$cpt_level2+1]['id'])) { echo ','; } } echo "]"; } } if($branch_level_id == "2") { $db->query("select id, contact_purpose_id, lastname, firstname, address_num, address_street, address_town, address_postal_code, enabled from ".$_SESSION['tablename']['contact_addresses']." where contact_id = ".$_REQUEST['branch_id']." order by lastname, firstname, address_num"); $children = array(); while($res = $db->fetch_object()) { $address = ''; $address = '('.$contactv2->get_label_contact($res->contact_purpose_id, $_SESSION['tablename']['contact_purposes']).') '; if ($res->lastname <> '' || $res->firstname <> ''){ $address .= strtoupper($func->show_string($res->lastname, true)) . ' ' . $func->show_string($res->firstname, true) . ' : '; } $address .= $func->show_string($res->address_num, true) . ' ' . $func->show_string($res->address_street, true) . ' ' . $func->show_string($res->address_postal_code, true) . ' ' . $func->show_string($res->address_town, true); array_push($children, array('id' => $res->id, 'address_label' => $address, 'enabled' => $res->enabled)); } if(count($children) > 0) { echo "["; for($cpt_level3=0; $cpt_level3< count($children); $cpt_level3++) { $color = ""; if ($children[$cpt_level3]['enabled'] == 'N') { $color = "style=\"color:red;\""; } //PB : if id in contact_addresses = 100, the address is not display in the contacts tree if ($children[$cpt_level3]['id'] == 100) { $children[$cpt_level3]['id'] = 10; } echo "{'id':'".$children[$cpt_level3]['id']."', 'txt':'".trim(addslashes($children[$cpt_level3]['address_label']))."', 'canhavechildren' : false, 'img' : 'page.gif'}"; if(isset($children[$cpt_level3+1]['id']) && !empty($children[$cpt_level3+1]['id'])) { echo ','; } } echo "]"; } } } ?>