private function allocateFieled()
 {
     extract($this->generateInfo());
     $userid = isset($_GET['uid']) ? $_GET['uid'] : FALSE;
     if (!is_numeric($userid) || $userid === FALSE) {
         $msgdata = array('data' => array('用户id不合法!'), 'link' => $gobackurl);
         goErrMsgPage($msgdata);
         exit;
     }
     $use_obj = new GetLoacalUserModel();
     $userinfo = $use_obj->getUserInfoById($userid);
     if (empty($userinfo)) {
         $msgdata = array('data' => array('用户信息不存在!'), 'link' => $gobackurl);
         goErrMsgPage($msgdata);
         exit;
     }
     //获得相应平台 文件夹信息
     $cat_obj = new amazonmessagecategoryModel();
     $catlist = $cat_obj->getAllCategoryInfoList(' order by category_name');
     //         print_r($catlist);exit;
     //print_r($catlist);exit;
     //获得用户权限
     $lp_obj = new LocalPowerAmazonModel();
     $userpower = $lp_obj->getUserInfo($userinfo['user_id'])['power'];
     // print_r($userpower);exit;
     $this->smarty->assign('userpower', explode(',', $userpower));
     $this->smarty->assign('gobackurl', $gobackurl);
     $this->smarty->assign('catlist', $catlist);
     $this->smarty->assign('submiturl', $submiturl);
     $this->smarty->assign('userinfo', $userinfo);
     $this->smarty->assign('sec_menue', $sec_menue);
     $this->smarty->assign('toplevel', 4);
     $this->smarty->assign('toptitle', 'Amazon message类别列表');
     $this->smarty->display('fieldAllocationAmazon.htm');
 }
 private function editMsgCategoryDataSubmit()
 {
     $data['name'] = isset($_POST['catname']) ? trim($_POST['catname']) : '';
     //名称
     $data['rules'] = isset($_POST['alphabet']) ? $_POST['alphabet'] : array();
     $data['account'] = isset($_POST['account']) ? trim($_POST['account']) : '';
     //账号
     $data['site'] = isset($_POST['site']) ? trim($_POST['site']) : '';
     $data['gmail'] = isset($_POST['gmail']) ? trim($_POST['gmail']) : '';
     $data['notes'] = isset($_POST['notes']) ? trim($_POST['notes']) : '';
     //备注
     extract($this->platformRelate($type));
     //特定平台相关信息
     $data['rules'] = array_intersect($data['rules'], generate_alphabet());
     //计算交集      以确保规则正确
     $data['rules'] = implode(',', $data['rules']);
     $data = array_map('mysql_real_escape_string', $data);
     $msgcat_obj = new amazonmessagecategoryModel();
     $lpower_obj = new LocalPowerAmazonModel();
     $global_obj = new GetLoacalUserModel();
     //print_r($_SESSION);
     $creater = $global_obj->getRealNameByGlobalId($_SESSION['globaluserid']);
     $data['creater'] = $creater['global_user_name'];
     $data['createtime'] = time();
     if ($data['account'] == -1) {
         //未分配账号
         $promptdata = array('data' => array('请分配账号!'), 'link' => $gobackurl);
         goErrMsgPage($promptdata);
     }
     $cid = isset($_POST['cid']) ? trim($_POST['cid']) : 0;
     //这下面是判断是新增分类还是编辑分类,然后执行相应操作
     if ($cid === 0) {
         //新增加分类
         try {
             $result = $msgcat_obj->addNewCategory($data);
         } catch (Exception $e) {
             $promptdata = array('data' => array('新增分类失败!'), 'link' => $gobackurl);
             goErrMsgPage($promptdata);
             exit;
         }
         if (empty($result)) {
             //不存在的id
             $promptdata = array('data' => array('不合法的id!'), 'link' => $gobackurl);
             goErrMsgPage($promptdata);
             exit;
         } else {
             /*----- 将新增的分类的权限给创建者 -----*/
             try {
                 $new_cid = $msgcat_obj->getCategoryInfoByCatname($data['name']);
                 $lpower_obj->updatePowerByAddClass($_SESSION['userId'], $new_cid['id']);
             } catch (Exception $e) {
                 print_r($new_cid);
                 /* $promptdata = array('data'=>array('权限更新失败!'), 'link'=>$gobackurl);
                   	goErrMsgPage($promptdata); */
                 exit;
             }
         }
     } else {
         //更新分类
         /*----- 如果是更新 则需确保数据分类是否和操作的向对应 -----*/
         $catinfo = $msgcat_obj->getCategoryInfoById($cid);
         if (empty($catinfo)) {
             //不存在的id
             $promptdata = array('data' => array('不合法的id!'), 'link' => $gobackurl);
             goErrMsgPage($promptdata);
             exit;
         }
         $result = $msgcat_obj->updateCategoryInfo($cid, $data);
     }
     if ($result) {
         $promptdata = array('data' => array('操作成功!'), 'link' => $gobackurl);
         goOkMsgPage($promptdata);
         exit;
     } else {
         $promptdata = array('data' => array('操作失败!'), 'link' => $gobackurl);
         goErrMsgPage($promptdata);
         exit;
     }
 }
 public function view_getAmazonMessageListByConditions()
 {
     $sender = isset($_GET['sender']) ? trim($_GET['sender']) : '';
     //关键字
     $sender = mysql_real_escape_string($sender);
     $status = isset($_GET['status']) ? $_GET['status'] : FALSE;
     //回复状态
     $category = isset($_GET['catid']) ? intval($_GET['catid']) : FALSE;
     //分类
     $from = isset($_GET['from']) ? $_GET['from'] : FALSE;
     $overtime = isset($_GET['overtime']) ? intval($_GET['overtime']) : FALSE;
     //发送者
     $name = isset($_GET['name']) ? trim($_GET['name']) : FALSE;
     $pagesize = isset($_SESSION['pagesize']) ? intval($_SESSION['pagesize']) : 200;
     $pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']) : $pagesize;
     //每页数量
     $cat_obj = new amazonmessagecategoryModel();
     /*----- 获得用户能够浏览的邮件目录 -----*/
     $Lp_obj = new LocalPowerAmazonModel();
     $fieldid = $Lp_obj->getAmazonPowerlist($_SESSION['userId']);
     //获得当前用户所属的邮件目录id
     $fieldid = empty($fieldid) ? array(-10) : explode(',', $fieldid);
     $category = in_array($category, $fieldid) ? $category : FALSE;
     if (empty($category)) {
         $catList = $fieldid;
         //在未输入搜索条件时列出该用户所有有权限的浏览的邮件目录id(数组形式)
     } else {
         $catList = array($category);
     }
     /*----- 获得用户所属文件夹 -----*/
     if (!empty($fieldid)) {
         $powerlist = $cat_obj->getFieldInfoByIds($fieldid, ' order by category_name');
         //通过目录id获得相关目录信息
     } else {
         $powerlist = array();
     }
     $wheresql = '';
     if (!empty($sender)) {
         //是否指定sender
         $wheresql .= " and sendid like '%{$sender}%' ";
     }
     if ($overtime == 24) {
         $status = FALSE;
     }
     if ($status !== FALSE) {
         //指定状态
         switch ($status) {
             case 1:
                 //回复完成
                 $wheresql .= " and status in (2,3)";
                 break;
             case 2:
                 //未回复
                 $wheresql .= " and status=0 ";
                 break;
             case 3:
                 //回复中
                 $wheresql .= " and status=1 ";
                 break;
             case 4:
                 //回复失败
                 $wheresql .= " and status=4 ";
                 break;
             default:
                 $wheresql .= "";
                 break;
         }
     }
     if ($from !== FALSE) {
         //url中包含from参数
         if ($from !== '') {
             //from参数不为空值
             $wheresql .= " and from_platform={$from} ";
         } else {
             $from = FALSE;
         }
     }
     //查询超过24小时还未回复的邮件
     if ($overtime == 24) {
         $time = time() - 86400;
         $wheresql .= " and recievetimestamp < {$time} and status =0 ";
     }
     //如果是选择From Member
     if ($from === FALSE && $overtime === FALSE) {
         $time = time() - 86400;
         $wheresql .= " and from_platform = '-1' and recievetimestamp > {$time}  ";
     }
     $class_sql = implode(', ', $catList);
     $wheresql .= " and classid in ({$class_sql}) and is_delete=0";
     //最终展示的是:登录的用户能够看到目录中的邮件
     $msg_obj = new amazonmessageModel();
     $mount = $msg_obj->getAmazonCountNumberByConditions($wheresql);
     //获得能够浏览的邮件数
     $page_obj = new Page($mount, $pagesize);
     $usercache = new UserCacheModel();
     if ($name !== FALSE) {
         if ($name == 'asc') {
             $orderby = ' order by sendid asc ';
         } else {
             $orderby = ' order by sendid desc ';
         }
     } else {
         $orderby = ' order by sendtime ';
     }
     $msglist = $msg_obj->getAmazonMessageListByConditions($wheresql . $orderby . $page_obj->limit);
     /* --- 格式化数据 ---*/
     foreach ($msglist as &$msgitem) {
         $msgitem['subject'] = urldecode($msgitem['subject']);
         if (strlen($msgitem['subject']) > 100) {
             $msgitem['subjectfm'] = mb_substr($msgitem['subject'], 0, 100) . '...';
         } else {
             $msgitem['subjectfm'] = $msgitem['subject'];
         }
         $msgitem['revtime'] = empty($msgitem['sendtime']) ? '' : date("Y 年 m 月 d 日 ", $msgitem['sendtime']) . '  ' . date("H时:i分:s秒", $msgitem['sendtime']);
         $catinfo = $cat_obj->getCategoryInfoById($msgitem['classid']);
         $msgitem['classname'] = $catinfo['category_name'];
         $userinfo = empty($msgitem['replyuser_id']) ? array('userName' => '') : $usercache->getUserInfoBySysId($msgitem['replyuser_id'], 0);
         $msgitem['username'] = $userinfo['userName'];
         $msgitem['retime'] = $msgitem['replytime'] ? date("Y-m-d \n H:i:s", $msgitem['replytime']) : '';
     }
     if ($mount > $pagesize) {
         //分页
         $pagestr = $page_obj->fpage(array(0, 2, 3, 4, 5, 6, 7, 8, 9));
     } else {
         $pagestr = $page_obj->fpage(array(0, 2, 3));
     }
     /*----- 获得分类文件夹列表 -----*/
     $categorylist = $cat_obj->getAllCategoryInfoList();
     //         print_r($categorylist);
     $this->smarty->assign('catlist', $categorylist);
     /*----- 获得分类列表 -----*/
     if ($from === FALSE) {
         $this->smarty->assign('third_menue', 1);
     } elseif ($from === '0') {
         $this->smarty->assign('third_menue', 2);
     } elseif ($from == 1) {
         $this->smarty->assign('third_menue', 3);
     } elseif ($from == 2) {
         $this->smarty->assign('third_menue', 4);
     }
     if ($overtime == 24) {
         $this->smarty->assign('third_menue', 5);
     }
     $urlquery = convertUrlQuery($_SERVER['QUERY_STRING']);
     unset($urlquery['name']);
     if ($name == 'asc') {
         $urlquery['name'] = 'desc';
     } else {
         $urlquery['name'] = 'asc';
     }
     $url = getUrlQuery($urlquery);
     //         echo $url, "\n";
     //         var_dump($urlquery);
     //print_r($msglist);
     $this->smarty->assign('url', $url);
     $this->smarty->assign('powerlist', $powerlist);
     $this->smarty->assign('from', $from);
     $this->smarty->assign('overtime', $overtime);
     $this->smarty->assign('sec_menue', 5);
     $this->smarty->assign('toplevel', 0);
     $this->smarty->assign('sender', $sender);
     $this->smarty->assign('category', $category);
     $this->smarty->assign('status', $status);
     $this->smarty->assign('pagestr', $pagestr);
     $this->smarty->assign('msglist', $msglist);
     $this->smarty->assign('categorylist', $arrlist);
     $this->smarty->assign('toptitle', 'message列表');
     $this->smarty->display('msglistAmazon.htm');
 }