Esempio n. 1
0
 function ProcessAlarm(AlmInstance $inst)
 {
     $dbhandle = A2Billing::DBHandle();
     global $verbose;
     if ($inst->ar_id) {
         // we cannot handle previous instances
         return;
     }
     $margin = $inst->alm_params['margin'];
     if (!isset($margin)) {
         $margin = 0.0;
     }
     $qry = str_dbparams($dbhandle, "SELECT cc_agent.id, credit, name, locale, email, climit, cc_alarm_run.id AS ar_id,\n\t\t\t\tcc_alarm_run.status AS ar_status\n\t\t\tFROM cc_agent LEFT JOIN cc_alarm_run ON ( cc_alarm_run.dataid = cc_agent.id\n\t\t\t\tAND cc_alarm_run.alid = %#1) \n\t\t\tWHERE (climit + credit ) < %#2 ;", array($inst->id, $margin));
     if ($verbose > 2) {
         echo "Query: " . $qry . "\n";
     }
     $res = $dbhandle->Execute($qry);
     if (!$res) {
         echo $dbhandle->ErrorMsg() . "\n";
     } else {
         if ($res->EOF) {
             if ($verbose > 2) {
                 echo "All agents have credit.\n";
             }
             $inst->Save(1);
             return;
         }
     }
     $neg_agents = array();
     while ($row = $res->fetchRow()) {
         if ($verbose > 2) {
             echo "Agent " . $row['name'] . " is low on credit.\n";
         }
         if (!empty($row['email'])) {
             $this->sendMail('agent-low-credit', $row['email'], $row['locale'], array(credit => $row['credit'], climit => $row['climit']));
         }
         $neg_agents[] = $row['name'] . ": " . $row['credit'] . "/" . $row['climit'];
     }
     $this->sendSysMail('sys-agent-low-credit', $inst, array(low_agents => implode("\n", $neg_agents)));
     $inst->Save();
 }
Esempio n. 2
0
 function ProcessAlarm(AlmInstance $inst)
 {
     echo "Process " . $inst->name . " !\n";
     $inst->Save();
 }