Exemplo n.º 1
0
 public function init()
 {
     $this->setAttrib('class', 'horizontal-form');
     $elements = array();
     $elements[] = $this->createElement('hidden', 'id_campaign')->setDecorators(array('ViewHelper'));
     $elements[] = $this->createElement('hidden', 'fk_id_department')->setDecorators(array('ViewHelper'));
     $elements[] = $this->createElement('text', 'campaign_title')->setDecorators($this->getDefaultElementDecorators())->addFilter('StringTrim')->addFilter('StringToUpper')->setAttrib('maxlength', 200)->setAttrib('class', 'm-wrap span12 focused')->setLabel('Naran Kampanha')->setRequired(true);
     $mapperConfig = new Admin_Model_Mapper_SmsConfig();
     $config = $mapperConfig->getConfig();
     $maxLength = $config->max_length - (strlen($config->sms_prefix) + strlen($config->sms_sufix) + 16);
     $elements[] = $this->createElement('textarea', 'content')->setDecorators($this->getDefaultElementDecorators())->addFilter('StringTrim')->setAttrib('class', 'm-wrap span12')->setAttrib('rows', 3)->setAttrib('maxlength', $maxLength)->setLabel('Mensajem')->setRequired(true);
     $elements[] = $this->createElement('text', 'date_scheduled')->setDecorators($this->getDefaultElementDecorators())->setAttrib('maxlength', 10)->setAttrib('class', 'm-wrap span12 date-mask date')->setLabel('Data atu haruka');
     $dbCampaignType = App_Model_DbTable_Factory::get('CampaignType');
     $rows = $dbCampaignType->fetchAll(array(), array('campaign_type'));
     $optCampaignType[''] = '';
     foreach ($rows as $row) {
         $optCampaignType[$row->id_campaign_type] = $row->campaign_type;
     }
     $elements[] = $this->createElement('select', 'fk_id_campaign_type')->setDecorators($this->getDefaultElementDecorators())->setLabel('Tipu Kampanha')->addMultiOptions($optCampaignType)->setRequired(true)->setAttrib('class', 'm-wrap span12 chosen');
     $mapperGroup = new Sms_Model_Mapper_Group();
     $rows = $mapperGroup->listGroupWithTotals();
     $optGroups = array();
     foreach ($rows as $row) {
         $optGroups[$row['id_sms_group']] = $row['sms_group_name'] . ' (' . $row['total'] . ')';
     }
     $elements[] = $this->createElement('multiCheckbox', 'group')->setDecorators(array('ViewHelper'))->addMultiOptions($optGroups)->setAttrib('onchange', 'Sms.Campaign.calcTotalSending( this );')->setAttrib('class', 'group-sending')->setRequired(true)->setSeparator('');
     $optWaitResponse['0'] = 'Lae';
     $optWaitResponse['1'] = 'Loos';
     $elements[] = $this->createElement('select', 'wait_response')->setDecorators($this->getDefaultElementDecorators())->setLabel('Hein Resposta')->addMultiOptions($optWaitResponse)->setValue('0')->setRequired(true)->setAttrib('class', 'm-wrap span12');
     $this->addElements($elements);
     App_Form_Toolbar::build($this, self::ID);
     $this->setDecorators($this->getDefaultFormDecorators());
 }
Exemplo n.º 2
0
 /**
  * 
  */
 public function indexAction()
 {
     $this->view->form = $this->_getForm($this->_helper->url('save'));
     $config = $this->_mapper->getConfig();
     if (!empty($config)) {
         $this->view->form->populate($config->toArray());
     }
 }
Exemplo n.º 3
0
 /**
  * 
  */
 public function calcAction()
 {
     $smsConfigMapper = new Admin_Model_Mapper_SmsConfig();
     $config = $smsConfigMapper->getConfig();
     $value = $this->_getParam('value');
     $type = $this->_getParam('type');
     if ($type == 'amount') {
         $total = number_format((int) $value * (double) $config['sms_unit_cost'], 2, '.', ',');
     } else {
         $total = floor((double) $value / (double) $config['sms_unit_cost']);
     }
     $this->_helper->json(array('value' => $total));
 }
Exemplo n.º 4
0
 /**
  * 
  * @param int $id
  * @return array
  */
 public function detailDepartment($id)
 {
     $dbDepartment = App_Model_DbTable_Factory::get('Department');
     $row = $dbDepartment->fetchRow(array('id_department = ?' => $id));
     if (empty($row)) {
         return array();
     } else {
         $data = $row->toArray();
         $mapperCredit = new Admin_Model_Mapper_SmsCredit();
         $totalBalance = $mapperCredit->getBalanceDepartment($row->id_department);
         $balance = (double) (empty($totalBalance) ? 0 : $totalBalance->balance);
         $mapperConfig = new Admin_Model_Mapper_SmsConfig();
         $config = $mapperConfig->getConfig();
         $sending = 0;
         if (!empty($balance)) {
             $sending = floor($balance / $config->sms_unit_cost);
         }
         $data['balance'] = $balance;
         $data['sending'] = $sending;
         return $data;
     }
 }
Exemplo n.º 5
0
 /**
  * 
  */
 public function calcSendingAction()
 {
     $user = Zend_Auth::getInstance()->getIdentity();
     // Get the User department
     $mapperDepartment = new Admin_Model_Mapper_Department();
     $department = $mapperDepartment->getDepartmentByUser($user->id_sysuser);
     // Get the groups with totals
     $mapperGroupsSms = new Sms_Model_Mapper_Group();
     $groups = $mapperGroupsSms->listGroupWithTotals();
     // Get the current sms config
     $mapperConfig = new Admin_Model_Mapper_SmsConfig();
     $config = $mapperConfig->getConfig();
     $groupsSelected = $this->_getParam('groups');
     $total = 0;
     $percent = 100;
     if (!empty($groupsSelected)) {
         foreach ($groups as $group) {
             if (in_array($group['id_sms_group'], $groupsSelected)) {
                 $total += (int) $group['total'];
             }
         }
     }
     $totalCurrency = $total * (double) $config->sms_unit_cost;
     if (!empty($department['balance'])) {
         $percent = $totalCurrency * 100 / $department['balance'];
     }
     $return = array('total' => $total, 'release' => $totalCurrency <= $department['balance'], 'percent' => $percent);
     $this->_helper->json($return);
 }
Exemplo n.º 6
0
 /**
  * 
  * @param int $id
  * @return Zend_Db_Table_Rowset
  */
 public function listContactsToSend($id, $limit = false)
 {
     $mapperGroupSms = new Sms_Model_Mapper_Group();
     $selectContacts = $mapperGroupSms->getSelectContacts();
     // Get the SMS Config
     $mapperConfig = new Admin_Model_Mapper_SmsConfig();
     $config = $mapperConfig->getConfig();
     $dbCampainGroup = App_Model_DbTable_Factory::get('CampaignHasSmsGroup');
     $dbCampainSent = App_Model_DbTable_Factory::get('CampaignSent');
     $selectContacts->join(array('cg' => $dbCampainGroup), 'cg.fk_id_sms_group = t.fk_id_sms_group', array())->joinLeft(array('cs' => $dbCampainSent), 'cs.fk_id_campaign = cg.fk_id_campaign ' . 'AND cs.fk_id_sms_group_contact = t.id_sms_group_contact', array('id_campaign_sent', 'attempts'))->where('cg.fk_id_campaign = ?', $id)->where('( cs.id_campaign_sent IS NULL')->orWhere('cs.status = ?', 'E')->where('cs.attempts < ? )', $config->error_attempts);
     if (!empty($limit)) {
         $selectContacts->limit($limit);
     }
     return $this->_dbTable->fetchAll($selectContacts);
 }
Exemplo n.º 7
0
 /**
  * 
  */
 public function retrieveSms()
 {
     $dbAdapter = Zend_Db_Table_Abstract::getDefaultAdapter();
     $dbAdapter->beginTransaction();
     try {
         // Save log informing that the robot has initied
         $this->saveLog('ROBOT HAHU BA BUKA SMS MAK SIMU');
         // Get the current SMS Config
         $mapperConfig = new Admin_Model_Mapper_SmsConfig();
         $smsConfig = $mapperConfig->getConfig();
         $messages = App_Util_Sms::retrieve($smsConfig->gateway_url);
         $dbSmsIncoming = App_Model_DbTable_Factory::get('SmsIncoming');
         $campaigns = array();
         foreach ($messages as $message) {
             $message = array_map('trim', $message);
             $message = array_map('urldecode', $message);
             $where = array('source = ?' => $message['source'], 'target = ?' => $message['target'], 'content = ?' => $message['content']);
             $msgReceived = $dbSmsIncoming->fetchRow($where);
             if (!empty($msgReceived)) {
                 continue;
             }
             $message['campaign'] = $this->_tryDiscoverCampaign($message, $smsConfig);
             if (!empty($message['campaign']) && !in_array($message['campaign'], $campaigns)) {
                 $campaigns[] = $message['campaign'];
             }
             $row = $dbSmsIncoming->createRow();
             $row->source = $message['source'];
             $row->target = $message['target'];
             $row->content = $message['content'];
             $row->date_time = $message['date_time'];
             $row->fk_id_campaign = $message['campaign'];
             $row->fk_id_sms_group_contact = $this->_tryDiscoverContact($message);
             $row->save();
         }
         if (!empty($campaigns)) {
             $this->_sendNotificationCampaigns($campaigns);
         }
         $this->saveLog('ROBOT REMATA BA BUKA SMS MAK SIMU');
         $dbAdapter->commit();
     } catch (Exception $ex) {
         $dbAdapter->rollBack();
         $this->saveLog('ERRO ROBO SIMU SMS: ' . $ex->getMessage());
     }
 }