public function addAction()
	{
		$errorMsg = null;
		$messages = new Admin_Models_MessageMapper();
		$usergroups = new System_Models_UsergroupMapper();
		$addForm = new Admin_Form_MessageSave();
		$addForm->getElement('groupId')->addMultiOption('0','所有用户');
		$addForm->submit->setLabel("发送信息");
		$usergroups->populateDd($addForm);
		$addForm = $messages->formValidator($addForm);
		if($this->getRequest()->isPost())
		{
			$formData = $this->getRequest()->getPost();
			if($addForm->isValid($formData))
			{
				$array = $messages->dataValidator($formData);
				$trigger = $array['trigger'];
				$errorMsg = $array['errorMsg'];
				if($trigger == 0)
				{
					$sendTime = date('Y-m-d,H:m');
					$groupId = $addForm->getValue('groupId');
					$message = new Admin_Models_Message();
					$message->setFromId($this->getUserId());
					$message->setTitle($addForm->getValue('title'));
					$message->setContent($addForm->getValue('content'));
					$message->setSendTime($sendTime);
					$message->setStatus(0);
					$messages->sendByGroup($groupId,$message);
					$this->_helper->flashMessenger->addMessage('信息: '.$message->getTitle().'发送成功。');
					$this->_redirect('/admin/message');
					}
					else
					{
						$addForm->populate($formData);
						}
				}
				else
				{
					$addForm->populate($formData);
					}
			}
		$this->view->controller = "add";
		$this->view->errorMsg = $errorMsg;
		$this->view->addForm = $addForm;
	}
	public function ajaxchangestatusAction()
	{
		$this->checkAuth();
		$this->_helper->layout()->disableLayout();
		$this->_helper->viewRenderer->setNoRender(true);
		$id = $this->_getParam('id');
		$status = $this->_getParam('status');
		$sendMsg = $this->_getParam('sendMsg');
		$improvements = new System_Models_ImprovementMapper();
		$improvement = new System_Models_Improvement();
		$improvements->find($id,$improvement);
		$improvement->setStatus($status);
		try
		{
			$improvements->save($improvement);
			if($sendMsg == 1)
			{
				$message = new Admin_Models_Message();
				$message->setTitle("系统消息: 您提交的系统问题的状态已被更改为: ".$improvement->getStatusCh());
				$message->setContent("您于".$improvement->getITime()."提交的关于".$improvement->getModNameCh()."模块的问题 : ".$improvement->getDescription()."已被处理, 当前状态为: ".$improvement->getStatusCh());
				$message->setFromId(1);
				$message->setToId($improvement->getUserId());
				$message->setSendTime(date('Y-m-d,H:i'));
				$message->setStatus(0);
				$messages = new Admin_Models_MessageMapper();
				$messages->sendByUserId($message);
				}
			echo "s";
			}
			catch(Exception $e)
			{
				echo "f";
				}
	}
	public function bapproveAction()
	{
		$groupId = $this->getGroupId();
		if($groupId != 4) 
		{
			$this->_redirect('/pment/mplan');
			}
		$id = $this->_getParam('id',0);
		
		if($id > 0)
		{
			//display plan info
			$mplans = new Pment_Models_MplanMapper();
			$mplan = new Pment_Models_Mplan();
			$errorMsg = null;
			$mplans->find($id,$mplan);
			$status = $mplan->getStatus();
			$materials = new Pment_Models_MaterialMapper();
			$condition = "planId";
			$arrayMaterials = $materials->fetchAllOrganize($id,$condition);
			$bhistories = new Pment_Models_BhistoryMapper();
			$arrayBhistories = $bhistories->fetchAllBhistories($id,0);
			$reviewers = new Pment_Models_ReviewerMapper();
			$arrayReviewers = $reviewers->fetchAllNames($id);
			
			if($this->getRequest()->isPost())
			{
				$btClicked = $this->getRequest()->getPost('btSub');
				$formData = $this->getRequest()->getPost();
				$array = $materials->bapprovcValidator($formData);
				$trigger = $array['trigger'];
				$errorMsg = $array['errorMsg'];
				if($trigger == 0)
				{
					$bhistory = new Pment_Models_Bhistory();
					$arrayMtrIds = $materials->fetchArryMtrIds($id);
					foreach($arrayMtrIds as $mtrId)
					{
						$material = new Pment_Models_Material();
						$materials->find($mtrId,$material);
						$material->setSpec($formData['spec_'.$mtrId]);
						$material->setAmountc($formData['amountc_'.$mtrId]);
						$material->setBudget($formData['budget_'.$mtrId]);
						$material->setBudgetTotal($formData['budgetTotal_'.$mtrId]);
						$material->setRemark($formData['remark_'.$mtrId]);
						$materials->save($material);
						}
					if($btClicked == "临时保存")
					{
						if($mplan->getStatus() == 1)
						{
							$mplan->setStatus(2);
							$bhistory->setEditType('材料计划首次审批');
							}
							else
							{
								$bhistory->setEditType('材料计划继续审批');
								}
						}
						elseif($btClicked =="确认并提交材料部审批")
						{
							$userId = $this->getUserId();
							$users = new System_Models_UserMapper();
							$approvcId = $users->getContactId($userId);
							$mplan->setStatus(3);
							$mplan->setApprovcId($approvcId);
							$mplan->setApprovcDate(date('Y-m-d,H:i'));
							
							//Send Email notifications to reviewers
							$reviewers = new Pment_Models_ReviewerMapper();
							$messages = new Admin_Models_MessageMapper();
							$message = new Admin_Models_Message();
							$arrayIds = $reviewers->fetchAllIds($mplan->getPlanId());
							$message->setFromId($this->getUserId());
							$message->setTitle(General_Models_Text::$text_mplan_validation_message_title);
							$message->setContent(General_Models_Text::$text_mplan_validation_message_content);
							$message->setSendTime(date("Y-m-d,H:i"));
							$message->setStatus(0);
							foreach($arrayIds as $userId)
							{
								$message->setToId($userId);
								$messages->sendByUserId($message);
								}
							$bhistory->setEditType('材料计划提交材料部');
							}
					$mplan->setApprovcRemark($formData['approvcRemark']);
					$mplans->save($mplan);
					$bhistory->setPlanId($id);
					$bhistory->setStatus(0);
					$userId = $this->getUserId();
					$users = new System_Models_UserMapper();
					$contactId = $users->getContactId($userId);
					$bhistory->setContactId($contactId);
					$bhistory->setEditDate(date('Y-m-d,H:i'));
					$bhistories->save($bhistory);
					$this->_redirect('/pment/mplan/bindex');
					}
				}
			$this->view->errorMsg = $errorMsg;
			$this->view->mplan = $mplan;
			$this->view->arrayReviewers = $arrayReviewers;
			$this->view->id = $id;
			$this->view->status = $status;
			$this->view->modelName = "预算部材料计划信息"; 
			$this->view->arrayBhistories = $arrayBhistories;
			//display material info
			$this->view->arrayMaterials = $arrayMaterials;
			}
			else
			{
				$this->_redirect('/pment/mplan');
				}
		}