function adminlistAction() { $this->_helper->layout->setLayout("layout_admin"); $request = $this->getRequest(); if (!$request->isPost()) { $plan_id = $request->getParam('plan_id'); } else { //create new plan and execute sql $formData = $request->getPost(); $sql = $formData['sql']; if ($sql == '' || $sql == null) { return; } else { $sql = 'select consumer.* ' . $sql; } $type = $formData['type']; $content = $formData['content']; //1.get all consumers $db = Zend_Registry::get('db'); $result = $db->query($sql); $consumers = $result->fetchAll(); //2. new a communicate plan $telephonePlanModel = new TelephonePlan(); $row = $telephonePlanModel->createRow(); $row->sql = $sql; $row->type = $type; $row->content = $content; //$row->total_consumers = count($consumers); //2011-04-08 ham.bao separate the sessions with admin $row->admin_id = $this->_currentAdmin->id; $row->edit_time = date("Y-m-d H:i:s"); $plan_id = $row->save(); //3. create sms $num = 0; foreach ($consumers as $consumer) { if ($consumer['phone'] == null || $consumer['phone'] == '') { continue; } if (preg_match('/1[35]\\d{9}/', $consumer['phone'], $rs) && count($rs) > 0) { $phone = $rs[0]; } else { continue; } $sms = new ShortMessage(); $row = $sms->createRow(); $row->consumer_id = $consumer['id']; $row->phone = $phone; $row->state = 'New'; $row->plan_id = $plan_id; $row->send_date = date("Y-m-d H:i:s"); $row->save(); $num++; } //4.update plan total number $telephonePlanModel = new TelephonePlan(); $set = array('total_consumers' => $num); $where = "id=" . $plan_id; $telephonePlanModel->update($set, $where); } //5.show consumers $db = Zend_Registry::get('db'); $select = $db->select(); $select->from('short_message', array('phone', 'state', 'send_date', 'plan_id'))->join('consumer', 'consumer.id = short_message.consumer_id', 'name')->where("short_message.plan_id = ?", $plan_id)->order('short_message.state asc')->order('short_message.id'); $this->view->sms = $db->fetchAll($select); $this->view->plan_id = $plan_id; }
function admindeleteAction() { $this->_helper->layout->setLayout("layout_admin"); $this->view->title = "Delete Plan"; if (!$this->_request->isPost()) { $id = (int) $this->_request->getParam('plan_id'); $type = $this->_request->getParam('type'); if ($id > 0) { //first, delete the telephone log or sms if ($type == "TELEPHONE") { $telephoneLogModel = new TelephoneLog(); $telephoneLogModel->deleteByPlan($id); } else { if ($type == "SMS") { $shortMessageModel = new ShortMessage(); $shortMessageModel->deleteByPlan($id); } else { } } //second, delete the plan $telephonePlanModel = new TelephonePlan(); $where = 'id = ' . $id; $telephonePlanModel->delete($where); } } //$this->_helper->json($type); $this->_redirect('conversation/adminindex'); }