db) { require_once "resources/classes/database.php"; $database = new database; $database->connect(); $this->db = $database->db; } } /** * Called when there are no references to a particular object * unset the variables used in the class */ public function __destruct() { foreach ($this as $key => $value) { unset($this->$key); } } /** * Get the destination menu * @var string $destination_type can be ivr, dialplan, call_center_contact or bridge * @var string $destination_name - current name * @var string $destination_value - current value */ public function select($destination_type, $destination_name, $destination_value) { //set the global variables global $db_type; //get the destinations if (!is_array($this->destinations)) { //get the array from the app_config.php files $config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php"); $x = 0; foreach ($config_list as &$config_path) { include($config_path); $x++; } $i = 0; foreach ($apps as $x => &$app) { if (isset($app['destinations'])) foreach ($app['destinations'] as &$row) { $this->destinations[] = $row; } } //put the array in order foreach ($this->destinations as $row) { $option_groups[] = $row['label']; } array_multisort($option_groups, SORT_ASC, $this->destinations); //add the sql and data to the array $x = 0; foreach ($this->destinations as $row) { if ($row['type'] = 'sql') { if (isset($row['sql'])) { if (is_array($row['sql'])) { $sql = trim($row['sql'][$db_type])." "; } else { $sql = trim($row['sql'])." "; } } else { $field_count = count($row['field']); $fields = ''; $c = 1; foreach ($row['field'] as $key => $value) { if ($field_count != $c) { $delimiter = ','; } else { $delimiter = ''; } $fields .= $value." as ".$key.$delimiter." "; $c++; } $sql = "select ".$fields; $sql .= " from v_".$row['name']." "; } if (isset($row['where'])) { $sql .= trim($row['where'])." "; } $sql .= "order by ".trim($row['order_by']); $sql = str_replace("\${domain_uuid}", $_SESSION['domain_uuid'], $sql); $sql = trim($sql); $statement = $this->db->prepare($sql); $statement->execute(); $result = $statement->fetchAll(PDO::FETCH_NAMED); unset($statement); $this->destinations[$x]['result']['sql'] = $sql; $this->destinations[$x]['result']['data'] = $result; } $x++; } $this->destinations[$x]['type'] = 'array'; $this->destinations[$x]['label'] = 'other'; $this->destinations[$x]['name'] = 'dialplans'; $this->destinations[$x]['field']['name'] = "name"; $this->destinations[$x]['field']['destination'] = "destination"; $this->destinations[$x]['select_value']['dialplan'] = "transfer:\${destination}"; $this->destinations[$x]['select_value']['ivr'] = "menu-exec-app:transfer \${destination}"; $this->destinations[$x]['select_label'] = "\${name}"; $y = 0; $this->destinations[$x]['result']['data'][$y]['label'] = 'check_voicemail'; $this->destinations[$x]['result']['data'][$y]['name'] = '*98'; $this->destinations[$x]['result']['data'][$y]['destination'] = '*98 XML ${context}'; $y++; $this->destinations[$x]['result']['data'][$y]['label'] = 'company_directory'; $this->destinations[$x]['result']['data'][$y]['name'] = '*411'; $this->destinations[$x]['result']['data'][$y]['destination'] = '*411 XML ${context}'; $y++; $this->destinations[$x]['result']['data'][$y]['label'] = 'hangup'; $this->destinations[$x]['result']['data'][$y]['name'] = 'hangup'; $this->destinations[$x]['result']['data'][$y]['application'] = 'hangup'; $this->destinations[$x]['result']['data'][$y]['destination'] = ''; $y++; $this->destinations[$x]['result']['data'][$y]['label'] = 'record'; $this->destinations[$x]['result']['data'][$y]['name'] = '*732'; $this->destinations[$x]['result']['data'][$y]['destination'] = '*732 XML ${context}'; $y++; } //remove special characters from the name $destination_id = str_replace("]", "", $destination_name); $destination_id = str_replace("[", "_", $destination_id); //set the css style $select_style = 'width: 200px;'; //add additional if (if_group("superadmin")) { $response = "\n"; $response .= "\n"; } //set default to false $select_found = false; $response .= " \n"; if (if_group("superadmin")) { $response .= ""; } //return the formatted destinations return $response; } /** * delete destinations */ public function delete($destinations) { if (permission_exists('destination_delete')) { //delete multiple destinations if (is_array($destinations)) { //get the action foreach($destinations as $row) { if ($row['action'] == 'delete') { $action = 'delete'; break; } } //delete the checked rows if ($action == 'delete') { foreach($destinations as $row) { if ($row['action'] == 'delete' or $row['checked'] == 'true') { //get the list of dialplan uuid $sql = "select * from v_destinations "; $sql .= "where destination_uuid = '".$row['destination_uuid']."';"; $prep_statement = $this->db->prepare($sql); $prep_statement->execute(); $destinations = $prep_statement->fetchAll(PDO::FETCH_NAMED); $row = $destinations[0]; //delete th dialplan $sql = "delete from v_dialplan_details "; $sql .= "where dialplan_uuid = '".$row['dialplan_uuid']."';"; $this->db->query($sql); unset($sql); //delete th dialplan $sql = "delete from v_dialplans "; $sql .= "where dialplan_uuid = '".$row['dialplan_uuid']."';"; $this->db->query($sql); unset($sql); //delete the destinations $sql = "delete from v_destinations "; $sql .= "where destination_uuid = '".$row['destination_uuid']."';"; $this->db->query($sql); unset($sql); } } unset($destinations); } } } } //end the delete function } /* $obj = new destinations; //$destinations = $obj->destinations; echo $obj->select('ivr', 'example1', 'menu-exec-app:transfer 32 XML voip.fusionpbx.com'); echo $obj->select('ivr', 'example2', ''); echo $obj->select('ivr', 'example3', ''); echo $obj->select('ivr', 'example4', ''); echo $obj->select('ivr', 'example5', ''); echo $obj->select('ivr', 'example6', ''); */ ?>