public function deleteprojectresourceAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $projectId = $this->_getParam('projectId');
         $projectresourceId = $this->_getParam('resourceProjectId');
         $empId = $this->_getParam('empId');
         $projResCount = '';
         $projectResourcesModel = new Timemanagement_Model_Projectresources();
         if ($projectresourceId) {
             $checkProjectResourceDependency = $projectResourcesModel->checkProjectResourceDependency($projectId, $empId);
             if ($checkProjectResourceDependency == 0) {
                 $data = array('is_active' => 0, 'modified' => gmdate("Y-m-d H:i:s"), 'modified_by' => $loginUserId);
                 $where = array('id=?' => $projectresourceId);
                 $Id = $projectResourcesModel->SaveorUpdateProjectResourceData($data, $where);
                 if ($Id == 'update') {
                     $task_resource_model = new Timemanagement_Model_Projecttaskresources();
                     $projTaskEmpData = array('is_active' => 0, 'modified' => gmdate("Y-m-d H:i:s"), 'modified_by' => $loginUserId);
                     $projTaskEmpWhere = array('project_id=?' => $projectId, 'emp_id=?' => $empId);
                     $update_data = array('is_active' => 0, 'modified' => gmdate("Y-m-d H:i:s"), 'modified_by' => $loginUserId);
                     $where_cond = array('emp_id=?' => $empId, 'project_id=?' => $projectId);
                     $Id = $task_resource_model->SaveorUpdateProjectTaskResourceData($update_data, $where_cond);
                     //sapp_Global::send_configuration_mail("Default Task", $taskData[0]['task']);
                     $messages['message'] = 'Resource deleted successfully.';
                     $messages['msgtype'] = 'success';
                 } else {
                     $messages['message'] = 'Resource cannot be deleted.';
                     $messages['msgtype'] = 'error';
                 }
             } else {
                 $messages['message'] = 'Resource started working in project.';
                 $messages['msgtype'] = 'error';
             }
         }
         $this->_helper->json(array('message' => $messages['message'], 'status' => $messages['msgtype']));
     }
 }
 public function saveresourcesAction()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $projectTaskResourceModel = new Timemanagement_Model_Projecttaskresources();
         if ($this->getRequest()->getPost()) {
             $projectId = $this->_getParam('projectId');
             $oldRes = $this->_getParam('oldRes');
             $newRes = $this->_getParam('newRes');
             $taskId = $this->_getParam('taskId');
             $projectTaskId = $this->_getParam('projectTaskId');
             $oldRes_arr = $newRes_arr = array();
             if (isset($oldRes) && $oldRes != '') {
                 $projRes = trim($oldRes, ",");
                 $oldRes_arr = explode(",", $oldRes);
             }
             if (isset($newRes) && $newRes != '') {
                 $projRes = trim($newRes, ",");
                 $newRes_arr = explode(",", $newRes);
             }
             if (!empty($newRes_arr)) {
                 foreach ($newRes_arr as $newRess) {
                     if (in_array($newRess, $oldRes_arr)) {
                         $key = array_search($newRess, $oldRes_arr);
                         unset($oldRes_arr[$key]);
                         // check already exists or not
                         continue;
                     } else {
                         $checkprojTaskResRecExists = $projectTaskResourceModel->isTaskAssigned(trim($projectId), trim($taskId), trim($newRess));
                         if (empty($checkprojTaskResRecExists)) {
                             $projectTaskResourceData = array('project_id' => trim($projectId), 'task_id' => trim($taskId), 'project_task_id' => trim($projectTaskId), 'emp_id' => trim($newRess), 'created_by' => $loginUserId, 'created' => gmdate("Y-m-d H:i:s"), 'is_active' => 1, 'modified_by' => $loginUserId, 'modified' => gmdate("Y-m-d H:i:s"));
                             $result = $projectTaskResourceModel->SaveorUpdateProjectTaskResourceData($projectTaskResourceData, '');
                         }
                     }
                 }
             }
             if (!empty($oldRes_arr)) {
                 // now $oldRes_arr contains removed res id's
                 foreach ($oldRes_arr as $removedRes) {
                     $projectTaskResourceData_remove = array('is_active' => 0, 'modified_by' => $loginUserId, 'modified' => gmdate("Y-m-d H:i:s"));
                     $where = array('project_id=?' => trim($projectId), 'project_task_id=?' => trim($projectTaskId), 'emp_id=?' => trim($removedRes));
                     $result = $projectTaskResourceModel->SaveorUpdateProjectTaskResourceData($projectTaskResourceData_remove, $where);
                 }
             }
             $this->_helper->json(array('message' => 'success', 'status' => 'Resource assigned to tasks successfully.'));
         }
     }
 }