function report_edit_form_submit($data)
{
    $error = report_validate($data);
    if (!empty($error)) {
        return FALSE;
    } else {
        $report = new Report();
        $update = $report->update($data);
        if ($update['code'] == 200) {
            return report_list($data['id']);
        }
    }
}
 function admincreatebatchAction()
 {
     $this->_helper->layout->setLayout("layout_admin");
     $db = Zend_Registry::get('db');
     $this->view->adminid = $this->_currentAdmin->id;
     if ($this->_request->isPost()) {
         // validate report_id
         $displayedreport_ids = $report_ids = $this->_request->getParam('reportInBatch');
         $campaignId = $this->_request->getParam('id');
         $reportBatchModel = new ReportBatch();
         $len = count($report_ids);
         for ($i = 0; $i < $len; $i++) {
             $reportBatch = $reportBatchModel->fetchRow("report_ids like '%," . $report_ids[$i] . ",%'");
             if ($reportBatch != null) {
                 //					unset($report_ids[$i]);
                 $this->_flashMessenger->addMessage("The Selected report conflicted, choose again please!");
                 $this->_helper->redirector('adminindex', 'report');
                 //					return;
             }
         }
         if (count($report_ids) > 0) {
             $currentTime = date("Y-m-d H:i:s");
             // create batch record
             $reportBatchModel = new ReportBatch();
             $reportBatch = $reportBatchModel->createRow();
             $reportBatch->start_datetime = $currentTime;
             //2011-04-08 ham.bao separate the sessions with admin
             $reportBatch->admin_id = $this->_currentAdmin->id;
             $reportBatch->report_ids = "," . implode(",", $report_ids) . ",";
             $reportBatch->state = 'NEW';
             $reportBatch->campaign_id = $campaignId;
             $reportBatch->save();
             $this->view->batchId = $reportBatch->id;
             //rock selected reports
             $reportModel = new Report();
             $db2 = $reportModel->getAdapter();
             $set = array('state' => 'LOCKED');
             $where = $db2->quoteInto('id in (' . implode(',', $report_ids) . ')');
             $rows_affected = $reportModel->update($set, $where);
         }
     } else {
         $batch_id = $this->_request->getParam('batch_id');
         $reportBatchModel = new ReportBatch();
         $reportBatch = $reportBatchModel->fetchRow('id  = ' . $batch_id);
         $displayedreport_ids = explode(',', substr($reportBatch['report_ids'], 1, strlen($reportBatch['report_ids']) - 2));
         $campaignId = $reportBatch['campaign_id'];
         $this->view->batchId = $reportBatch['id'];
     }
     //		Zend_Debug::dump($this->view->batchId);
     if (count($displayedreport_ids) == 0) {
         return;
     }
     //campagin
     $campaignModel = new Campaign();
     $this->view->campaign = $campaignModel->fetchRow('id = ' . $campaignId);
     // show the selected reports
     $select = $db->select();
     $select->from('report', 'report.*');
     $select->join('consumer', 'report.consumer_id = consumer.id', array('consumer.email', 'consumer.login_phone', 'consumer.name'));
     $select->join('campaign_invitation', 'campaign_invitation.consumer_id = report.consumer_id and report.campaign_id = campaign_invitation.campaign_id', 'campaign_invitation.state as cistate');
     $select->where('report.id in (' . implode(',', $displayedreport_ids) . ')');
     $select->order('report.create_date desc');
     $this->view->AllReports = $db->fetchAll($select);
     // 2011-09-21 bruce.liu show selected reports and admin_name (who approved the report )
     $num = 0;
     foreach ($this->view->AllReports as $rep) {
         $select_admin = $db->select();
         $select_admin->from('report_batch', 'report_batch.admin_id');
         $select_admin->join('admin', 'admin.id = report_batch.admin_id', 'admin.name');
         $select_admin->where('FIND_IN_SET(' . $rep['id'] . ',report_batch.report_ids) > 0');
         $this->admin_name = $db->fetchAll($select_admin);
         $this->view->AllReports[$num]['name'] = $this->admin_name[0]['name'];
         $num++;
     }
     //get report amount for each member
     $selectReportAmount = $db->select();
     $selectReportAmount->from('report', array('count(*)', 'consumer_id'))->group('consumer_id');
     $reportAmounts = $db->fetchAll($selectReportAmount);
     $this->view->reportAmountArray = array();
     foreach ($reportAmounts as $reportAmonut) {
         $i = $reportAmonut["consumer_id"];
         $this->view->reportAmountArray[$i] = $reportAmonut["count(*)"];
     }
     $selectReportAmount->where("campaign_id = ?", $campaignId);
     $reportCampaignAmonuts = $db->fetchAll($selectReportAmount);
     $this->view->reportCampaignAmountArray = array();
     foreach ($reportCampaignAmonuts as $reportCampaignAmonut) {
         $i = $reportCampaignAmonut["consumer_id"];
         $this->view->reportCampaignAmountArray[$i] = $reportCampaignAmonut["count(*)"];
     }
     //get report point
     $select2 = $db->select();
     $select2->from('reward_point_transaction_record', 'reward_point_transaction_record.*');
     $select2->where('reward_point_transaction_record.transaction_id = 1');
     $AllRecords = $db->fetchAll($select2);
     $recordsArray = array();
     foreach ($AllRecords as $record) {
         $i = $record["id"];
         $recordsArray[$i] = $record["point_amount"];
     }
     $this->view->pointArray = array();
     $this->view->reportArray = array();
     foreach ($this->view->AllReports as $report) {
         if ($report['reward_point_transaction_record_id'] != null && array_key_exists($report['reward_point_transaction_record_id'], $recordsArray)) {
             $j = $report["id"];
             $k = $report['reward_point_transaction_record_id'];
             $this->view->pointArray[$j] = $recordsArray[$k];
         }
     }
     //get report reply
     $select3 = $db->select();
     $select3->from('reply', array('report_id', 'status'));
     $allReplys = $db->fetchAll($select3);
     $this->view->allReplysArray = array();
     foreach ($allReplys as $reply) {
         $i = $reply["report_id"];
         $this->view->allReplysArray[$i] = $reply["status"];
     }
 }
}
if ($exists && isset($_POST['report_edit'])) {
    $p_message = trim(strip_tags($_POST['message']));
    $success = true;
    $errors = array();
    if ($p_message == '') {
        $success = false;
        array_push($errors, "The message field is required!");
    }
    if ($p_message != '' && !preg_match('/^[\\s\\S]{0,200}$/u', $p_message)) {
        $success = false;
        array_push($errors, "The message must be no more than 200 character long.");
    }
    if ($success) {
        $update = array('message' => $p_message);
        Report::update($g_id, $update);
        $report = Report::get_one($g_id);
    }
}
include "page-header.php";
?>

<div id="wrapper">

	<?php 
include "page-left.php";
?>

	<div id="content">
			
		<form name="form_report_edit" id="form_report_edit" method="post" enctype='application/x-www-form-urlencoded' accept-charset="UTF-8" class="form">