Esempio n. 1
0
/**
 * Summary of processSubscriptions
 * @param mixed $event_name Event name
 * @param mixed $details    Details (default '')
 * @return int|void
 */
function processSubscriptions($event_name, $details = '')
{
    if (!defined('SETTINGS_HOOK_EVENT_' . strtoupper($event_name))) {
        return 0;
    }
    $data = json_decode(constant('SETTINGS_HOOK_EVENT_' . strtoupper($event_name)), true);
    if (is_array($data)) {
        foreach ($data as $k => $v) {
            $module_name = $k;
            $filter_details = $v;
            $modulePath = DIR_MODULES . $module_name . '/' . $module_name . '.class.php';
            if (file_exists($modulePath)) {
                include_once $modulePath;
                $module_object = new $module_name();
                if (method_exists($module_object, 'processSubscription')) {
                    $module_object->processSubscription($event_name, $details);
                }
            }
        }
    }
    postToWebSocket($event_name, $details, 'PostEvent');
}
Esempio n. 2
0
 /**
 * FrontEnd
 *
 * Module frontend
 *
 * @access public
 */
 function usual(&$out)
 {
     global $session;
     if ($this->action == 'addevent') {
         global $mode;
         $this->mode = $mode;
         if ($this->mode == 'update') {
             global $type;
             global $window;
             global $details;
             global $terminal_to;
             global $user_to;
             $event = array();
             $event['EVENT_TYPE'] = $type;
             $event['WINDOW'] = $window;
             $event['DETAILS'] = $details;
             $event['TERMINAL_TO'] = $terminal_to;
             $event['TERMINAL_FROM'] = $session->data['TERMINAL'];
             $event['USER_TO'] = $user_to;
             $event['USER_FROM'] = $session->data['USERNAME'];
             $event['ADDED'] = date('Y-m-d H:i:s');
             $event['EXPIRE'] = date('Y-m-d H:i:s', time() + 5 * 60);
             //5 minutes expire
             SQLInsert('events', $event);
             postToWebSocket('TERMINAL_EVENT', $event, 'PostEvent');
         }
         $terminals = SQLSelect("SELECT * FROM terminals ORDER BY TITLE");
         $total = count($terminals);
         for ($i = 0; $i < $total; $i++) {
             if ($terminals[$i]['NAME'] == $session->data['TERMINAL']) {
                 $terminals[$i]['SELECTED'] = 1;
                 $out['TERMINAL_TITLE'] = $terminals[$i]['TITLE'];
             }
         }
         $out['TERMINALS'] = $terminals;
         $users = SQLSelect("SELECT * FROM users ORDER BY NAME");
         $total = count($users);
         for ($i = 0; $i < $total; $i++) {
             if ($users[$i]['USERNAME'] == $session->data['USERNAME']) {
                 $users[$i]['SELECTED'] = 1;
                 $out['USER_TITLE'] = $users[$i]['NAME'];
             }
         }
         $out['USERS'] = $users;
     }
     if ($this->action == 'getnextevent') {
         if (!$session->data['TERMINAL']) {
             $session->data['TERMINAL'] = 'temp' . date('YmdHis');
         }
         //echo "next event for ".$session->data['USERNAME']." on ".$session->data['TERMINAL'];//.date('H:i:s')
         SQLExec("DELETE FROM events WHERE EXPIRE<NOW() AND EVENT_TYPE!='system'");
         $qry = "1";
         //$qry.=" AND TERMINAL_FROM!='".DBSafe($session->data['TERMINAL'])."'";
         $qry .= " AND EVENT_TYPE!='system'";
         $qry .= " AND PROCESSED=0";
         $qry .= " AND (TERMINAL_TO='*' OR TERMINAL_TO='" . DBSafe($session->data['TERMINAL']) . "')";
         $qry .= " AND (USER_TO='*' OR USER_TO='" . DBSafe($session->data['USERNAME']) . "')";
         $event = SQLSelectOne("SELECT * FROM events WHERE {$qry} ORDER BY ADDED");
         if ($event['ID']) {
             $res = $event['ID'] . '|' . $event['EVENT_TYPE'] . '|' . $event['WINDOW'] . '|' . str_replace("\n", '\\n', $event['DETAILS']);
             echo $res;
             $event['PROCESSED'] = 1;
             SQLUpdate('events', $event);
         }
         exit;
     }
 }
Esempio n. 3
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function setProperty($property, $value, $no_linked = 0)
 {
     startMeasure('setProperty');
     startMeasure('setProperty (' . $property . ')');
     $id = $this->getPropertyByName($property, $this->class_id, $this->id);
     $old_value = '';
     $cached_name = 'MJD:' . $this->object_title . '.' . $property;
     if ($id) {
         $prop = SQLSelectOne("SELECT * FROM properties WHERE ID='" . $id . "'");
         $v = SQLSelectOne("SELECT * FROM pvalues WHERE PROPERTY_ID='" . (int) $id . "' AND OBJECT_ID='" . (int) $this->id . "'");
         $old_value = $v['VALUE'];
         $v['VALUE'] = $value;
         if ($v['ID']) {
             $v['UPDATED'] = date('Y-m-d H:i:s');
             if ($old_value != $value) {
                 SQLUpdate('pvalues', $v);
             } else {
                 SQLExec("UPDATE pvalues SET UPDATED='" . $v['UPDATED'] . "' WHERE ID='" . $v['ID'] . "'");
             }
         } else {
             $v['PROPERTY_ID'] = $id;
             $v['OBJECT_ID'] = $this->id;
             $v['VALUE'] = $value;
             $v['UPDATED'] = date('Y-m-d H:i:s');
             $v['ID'] = SQLInsert('pvalues', $v);
         }
         //DebMes(" $id to $value ");
     } else {
         $prop = array();
         $prop['OBJECT_ID'] = $this->id;
         $prop['TITLE'] = $property;
         $prop['ID'] = SQLInsert('properties', $prop);
         $v['PROPERTY_ID'] = $prop['ID'];
         $v['OBJECT_ID'] = $this->id;
         $v['VALUE'] = $value;
         $v['UPDATED'] = date('Y-m-d H:i:s');
         $v['ID'] = SQLInsert('pvalues', $v);
     }
     saveToCache($cached_name, $value);
     if (function_exists('postToWebSocket')) {
         postToWebSocket($this->object_title . '.' . $property, $value);
     }
     if ($this->keep_history > 0) {
         $prop['KEEP_HISTORY'] = $this->keep_history;
     }
     if (isset($prop['KEEP_HISTORY']) && $prop['KEEP_HISTORY'] > 0) {
         $q_rec = array();
         $q_rec['VALUE_ID'] = $v['ID'];
         $q_rec['ADDED'] = date('Y-m-d H:i:s');
         $q_rec['VALUE'] = $value;
         $q_rec['OLD_VALUE'] = $old_value;
         $q_rec['KEEP_HISTORY'] = $prop['KEEP_HISTORY'];
         SQLInsert('phistory_queue', $q_rec);
     }
     if (isset($prop['ONCHANGE']) && $prop['ONCHANGE']) {
         global $property_linked_history;
         if (!$property_linked_history[$property][$prop['ONCHANGE']]) {
             $property_linked_history[$property][$prop['ONCHANGE']] = 1;
             global $on_change_called;
             $params = array();
             $params['PROPERTY'] = $property;
             $params['NEW_VALUE'] = (string) $value;
             $params['OLD_VALUE'] = (string) $old_value;
             $this->callMethod($prop['ONCHANGE'], $params);
             unset($property_linked_history[$property][$prop['ONCHANGE']]);
         }
     }
     if (isset($v['LINKED_MODULES']) && $v['LINKED_MODULES']) {
         // TO-DO !
         if (!is_array($no_linked) && $no_linked) {
             return;
         } elseif (!is_array($no_linked)) {
             $no_linked = array();
         }
         $tmp = explode(',', $v['LINKED_MODULES']);
         $total = count($tmp);
         for ($i = 0; $i < $total; $i++) {
             $linked_module = trim($tmp[$i]);
             if (isset($no_linked[$linked_module])) {
                 continue;
             }
             if (file_exists(DIR_MODULES . $linked_module . '/' . $linked_module . '.class.php')) {
                 include_once DIR_MODULES . $linked_module . '/' . $linked_module . '.class.php';
                 $module_object = new $linked_module();
                 if (method_exists($module_object, 'propertySetHandle')) {
                     $module_object->propertySetHandle($this->object_title, $property, $value);
                 }
             }
         }
     }
     /*
      $h=array();
      $h['ADDED']=date('Y-m-d H:i:s');
      $h['OBJECT_ID']=$this->id;
      $h['VALUE_ID']=$v['ID'];
      $h['OLD_VALUE']=$old_value;
      $h['NEW_VALUE']=$value;
      SQLInsert('history', $h);
     */
     endMeasure('setProperty (' . $property . ')', 1);
     endMeasure('setProperty', 1);
 }