コード例 #1
0
ファイル: systemsortprocess.php プロジェクト: ddrmoscow/queXS
        $sql = "UPDATE `questionnaire_sample_exclude_priority`\r\n      SET sortorder = NULL\r\n      WHERE sortorder IS NOT NULL\r\n      AND questionnaire_id = '{$questionnaire_id}'";
        $db->Execute($sql);
        //Sort sample list where attached to this questionnaire
        $sql = "SELECT s.sample_id as sample_id,qs.questionnaire_id as questionnaire_id\r\n      FROM sample as s\r\n      JOIN (questionnaire_sample as qs, questionnaire as q, sample_import as si) on (qs.sample_import_id = s.import_id and si.sample_import_id = s.import_id and q.questionnaire_id = qs.questionnaire_id AND q.questionnaire_id = '{$questionnaire_id}' AND qs.allow_new = 1)\r\n      LEFT JOIN `case` as c on (c.sample_id = s.sample_id and c.questionnaire_id = qs.questionnaire_id)\r\n      LEFT JOIN call_restrict as cr on (cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)\r\n      LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))\r\n      LEFT JOIN questionnaire_sample_exclude_priority AS qsep ON (qsep.questionnaire_id = qs.questionnaire_id AND qsep.sample_id = s.sample_id)\r\n      WHERE c.case_id is NULL\r\n      AND ((qsep.questionnaire_id IS NULL) or qsep.exclude = 0)\r\n      AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL)\r\n      AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL)\r\n      AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = qs.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0\r\n      GROUP BY s.sample_id,qs.questionnaire_id\r\n      ORDER BY qsep.priority DESC, rand() * qs.random_select, qs.sort_order ASC";
        $rs = $db->GetAll($sql);
        $i = 1;
        foreach ($rs as $r) {
            $sql = "INSERT INTO questionnaire_sample_exclude_priority (questionnaire_id,sample_id,exclude,priority,sortorder)\r\n                    VALUES ('{$r['questionnaire_id']}', '{$r['sample_id']}', 0, 50,'{$i}')\r\n                    ON DUPLICATE KEY UPDATE sortorder = '{$i}'";
            $db->Execute($sql);
            $i++;
        }
        $result = $db->CompleteTrans();
        $time_end = microtime(true);
        $timer = $time_end - $time_start;
        if ($result) {
            print T_("Completed sort") . ". " . T_("This task took") . ": {$timer} " . T_("seconds");
        } else {
            print T_("Failed to complete sort") . ". " . T_("This task took") . ": {$timer} " . T_("seconds");
        }
    }
    for ($i = 0; $i < SYSTEM_SORT_MINUTES * 60; $i += $sleepinterval) {
        if (is_process_killed($process_id)) {
            break;
        }
        sleep($sleepinterval);
    }
    process_clear_log();
}
disable_systemsort();
ob_get_contents();
ob_end_clean();
コード例 #2
0
ファイル: icrmonitor.php プロジェクト: bimbam123/quexf
 *
 */
include "../functions/functions.import.php";
include "../functions/functions.xhtml.php";
include "../functions/functions.process.php";
xhtml_head(T_("Monitor ICR process"), true, array("../css/table.css"), false, false);
if (isset($_GET['p'])) {
    $p = intval($_GET['p']);
    if (isset($_GET['kill'])) {
        kill_process($p);
    }
    if (isset($_GET['force_kill'])) {
        end_process($p);
    }
    print "<h1>" . T_("Process") . " {$p}</h1>";
    if (is_process_killed($p)) {
        print "<h3>" . T_("Kill signal sent: Please wait...") . "</h3>";
        print "<p><a href='?force_kill'>" . T_("Mark the proces as killed (i.e. when the server is rebooted)") . "</a></p>";
    } else {
        print "<p><a href='?kill=kill'>" . T_("Kill the running process") . "</a> (" . T_("may take up to a few minutes to take effect") . ")</p>";
    }
    $d = process_get_data($p);
    if ($d !== false) {
        xhtml_table($d, array('process_log_id', 'datetime', 'data'), array(T_("Log id"), T_("Date"), T_("Log entry")));
    }
} else {
    global $db;
    $sql = "SELECT process_id\n\t\tFROM process\n\t\tWHERE stop IS NULL\n\t\tAND type = 2";
    $rs = $db->GetAll($sql);
    if (!empty($rs)) {
        foreach ($rs as $r) {
コード例 #3
0
ファイル: functions.voip.php プロジェクト: ddrmoscow/queXS
 /**
  *  Watch for Asterisk events and make changes to the queXS databse if
  *  appropriate
  *
  *  
  */
 function watch($process_id = false)
 {
     /**
      * Process file
      */
     if ($process_id) {
         include_once dirname(__FILE__) . '/../functions/functions.process.php';
     }
     $line = "";
     if ($this->socket === false) {
         return false;
     }
     //Set initial extension status
     $this->updateAllExtensionStatus();
     $in = true;
     $time = time();
     //Watch for events
     do {
         if (!$this->isConnected() || $this->socket === false || $in === FALSE) {
             fclose($this->socket);
             print T_("Disconnected") . "\n";
             $this->connect(VOIP_SERVER, VOIP_ADMIN_USER, VOIP_ADMIN_PASS, true);
             if ($this->isConnected()) {
                 print T_("Reconnected") . "\n";
             }
         }
         $in = fgets($this->socket, 4096);
         //print "IN: $in\n";
         /**
          * When we have reached the end of a message, process it
          *
          */
         if ($in == "\r\n") {
             //print "PROCESS: ";
             /**
              * The call is ringing
              */
             if (preg_match("{Event: Dial.*SubEvent: Begin.*Channel: ((SIP/|IAX2/)[0-9]+)}is", $line, $regs)) {
                 list($call_id, $case_id) = $this->getCallId($regs[1]);
                 if ($call_id != 0) {
                     print T_("Ringing") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id={$case_id}\">{$case_id}</a>\n";
                     $this->setState($call_id, 2);
                 }
             } else {
                 if (preg_match("{Event: Bridge.*Channel1: ((SIP/|IAX2/)[0-9]+)}is", $line, $regs)) {
                     list($call_id, $case_id) = $this->getCallId($regs[1]);
                     if ($call_id != 0) {
                         print T_("Answered") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id={$case_id}\">{$case_id}</a>\n";
                         $this->setState($call_id, 3);
                     }
                 } else {
                     if (preg_match("{Event: Hangup.*Channel: ((SIP/|IAX2/)[0-9]+)}is", $line, $regs)) {
                         list($call_id, $case_id) = $this->getCallId($regs[1]);
                         if ($call_id != 0) {
                             print T_("Hangup") . T_(" Extension ") . $regs[1] . " " . T_("Case id") . ": <a href=\"supervisor.php?case_id={$case_id}\">{$case_id}</a>\n";
                             $this->setState($call_id, 4, true);
                         }
                     } else {
                         if (preg_match("{Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Unregistered}is", $line, $regs)) {
                             print T_("Unregistered") . T_(" Extension ") . $regs[1] . "\n";
                             $this->setExtensionStatus($regs[1], false);
                         } else {
                             if (preg_match("{Event: PeerStatus.*Peer: ((SIP/|IAX2/)[0-9]+).*PeerStatus: Registered}is", $line, $regs)) {
                                 print T_("Registered") . T_(" Extension ") . $regs[1] . "\n";
                                 $this->setExtensionStatus($regs[1], true);
                             }
                         }
                     }
                 }
             }
             //print $line . "\n\n";
             $line = "";
         } else {
             if ($in !== FALSE) {
                 /**
                  * Append the lines to the message if we are not yet at the end of one
                  */
                 $line .= $in;
             }
         }
         @flush();
         if ($process_id && time() - $time > 10) {
             $this->dbReconnect();
             $this->keepWatching = !is_process_killed($process_id);
             $time = time();
         }
     } while ($this->keepWatching);
 }