예제 #1
0
 /**
  * @name viewAction
  *
  * This method is used to display the detail log info
  *
  *  @author Deepthi
  *  @version 1.0
  */
 public function viewAction()
 {
     $activitylog_model = new Default_Model_Activitylog();
     $logmanager_model = new Default_Model_Logmanager();
     $menu_model = new Default_Model_Menu();
     //Pop up layout
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $perPage = PERPAGE;
     $this->view->managemodule = 0;
     if ($this->getRequest()) {
         $id = $this->_request->getParam('id');
         $viewLinkArray = array('101', '102');
         // menu with view links
         $logManagarRecord = $logmanager_model->getLogManagerDataByID($id);
         $menuId = $logManagarRecord[0]['menuId'];
         $action = $logManagarRecord[0]['user_action'];
         switch ($action) {
             case 1:
                 $userAction = 'add';
                 break;
             case 2:
                 $userAction = 'edit';
                 break;
             default:
                 $userAction = '';
                 break;
         }
         $url = $menu_model->getMenusDataById($menuId);
         $modurl = ltrim($url[0]['url'], '/');
         if (isset($logManagarRecord[0]['log_details']) && !empty($logManagarRecord[0]['log_details'])) {
             $logdetails = '{"testjson":[' . $logManagarRecord[0]['log_details'] . ']}';
             $logarr = @get_object_vars(json_decode($logdetails));
             if (!empty($logarr)) {
                 $userArray = array();
                 $logarr['testjson'] = array_reverse($logarr['testjson']);
                 $this->logJsonCount = count($logarr['testjson']);
                 foreach ($logarr['testjson'] as $key => $curr) {
                     $currArray = @get_object_vars($curr);
                     $this->modArray[$key]['userid'] = $currArray['userid'];
                     if ($menuId != '142') {
                         if (in_array($menuId, $viewLinkArray)) {
                             $this->modArray[$key]['recordid'] = isset($currArray['recordid']) ? DOMAIN . $modurl . '/view/id/' . $currArray['recordid'] : '0';
                         } else {
                             $this->modArray[$key]['recordid'] = isset($currArray['recordid']) ? DOMAIN . $modurl . '/edit/id/' . $currArray['recordid'] : '0';
                         }
                     } else {
                         $this->view->managemodule = 1;
                         $this->modArray[$key]['recordid'] = $currArray['childrecordid'];
                     }
                     $this->modArray[$key]['date'] = $currArray['date'];
                     if (!in_array($currArray['userid'], $userArray)) {
                         array_push($userArray, $currArray['userid']);
                     }
                 }
                 $this->userNameArray = $activitylog_model->getuserNamesByIds($userArray);
                 if ($menuId != '61' && $menuId != '65') {
                     $this->view->viewrRecordFlag = true;
                 } else {
                     $this->view->viewrRecordFlag = false;
                 }
                 $this->view->mainArray = $this->modArray;
                 $this->view->userNameArray = $this->userNameArray;
                 $this->view->totalJsonCount = $this->logJsonCount;
                 $this->view->pageNo = 1;
                 $this->view->perPage = $perPage;
             } else {
                 $this->view->message = "No records found";
                 exit;
             }
         }
     }
 }
예제 #2
0
 public function activitylogreportAction()
 {
     try {
         $activitylog_model = new Default_Model_Activitylog();
         $logmanager_model = new Default_Model_Logmanager();
         $dashboardcall = $this->_getParam('dashboardcall');
         if ($dashboardcall == 'Yes') {
             $perPage = DASHBOARD_PERPAGE;
         } else {
             $perPage = PERPAGE;
         }
         $selectFields = array('menuname' => 'Menu', 'username' => 'User Name', 'empId' => 'Employee ID', 'useraction' => 'Action', 'modifieddate' => 'Modified Date');
         $selectColumns = array_keys($selectFields);
         $action = array('1' => 'Add', '2' => 'Edit', '3' => 'Delete', '5' => 'Cancel');
         $activityLogData = array();
         $splitArray = array();
         $pageNo = 1;
         $order = $funorder = 'Desc';
         $by = $sortby = 'last_modifieddate';
         $searchData = '';
         $lastpage = 0;
         if ($this->getRequest()->getPost()) {
             $this->_helper->layout->disableLayout();
         }
         if ($this->_request->getParam('pageNo') != '') {
             $pageNo = intval($this->_request->getParam('pageNo'));
         }
         if ($this->_request->getParam('per_page') != '') {
             $perPage = intval($this->_request->getParam('per_page'));
         }
         if ($this->_request->getParam('fields') != '') {
             $selectColumns = explode(',', $this->_request->getParam('fields'));
         }
         $finalArray = array();
         //POST with empty search fields
         if ($this->_request->getParam('hiddenusername') == '' && $this->_request->getParam('menu') == '' && $this->_request->getParam('useraction') == '' && $this->_request->getParam('modifieddate') == '') {
             if ($this->_request->getParam('sortby') != '') {
                 $by = $sortby = $this->_request->getParam('sortby');
                 $order = $funorder = $this->_request->getParam('order');
                 if ($sortby == 'userfullname') {
                     $by = '';
                     $usernameorder = $logmanager_model->getUsernameOrderForLog($order);
                     if (!empty($usernameorder)) {
                         $funorder = 'FIND_IN_SET(last_modifiedby,"' . $usernameorder . '")';
                     }
                 }
                 if ($sortby == 'employeeId') {
                     $by = '';
                     $empidorder = $logmanager_model->getEmpidOrderForLog($order);
                     if (!empty($empidorder)) {
                         $funorder = 'FIND_IN_SET(last_modifiedby,"' . $empidorder . '")';
                     }
                 }
                 if ($sortby == 'menuname') {
                     $by = '';
                     $menunameorder = $logmanager_model->getMenuOrderForLog($order);
                     if (!empty($menunameorder)) {
                         $funorder = 'FIND_IN_SET(menuId,"' . $menunameorder . '")';
                     }
                 }
             }
             $activityLogData = $logmanager_model->getLogManagerDataReport($by, $funorder, $pageNo, $perPage, $searchData, array('*'));
             $activityLogCount = $activitylog_model->getLogManagerCount();
             $menuArray = array();
             $userArray = array();
             if (count($activityLogData) > 0) {
                 $lastpage = ceil($activityLogCount / $perPage);
                 foreach ($activityLogData as $activitylog) {
                     if (isset($activitylog['menuId'])) {
                         if (!in_array($activitylog['menuId'], $menuArray)) {
                             array_push($menuArray, $activitylog['menuId']);
                         }
                     }
                     if (isset($activitylog['last_modifiedby'])) {
                         if (!in_array($activitylog['last_modifiedby'], $userArray)) {
                             array_push($userArray, $activitylog['last_modifiedby']);
                         }
                     }
                 }
             }
             $menuNameArray = $activitylog_model->getMenuNamesByIds($menuArray);
             $userNameArray = $activitylog_model->getuserNamesByIds($userArray);
             if (count($activityLogData) > 0) {
                 foreach ($activityLogData as $key => $activitylog) {
                     if (in_array('menuname', $selectColumns)) {
                         $finalArray[$key]['menuname'] = isset($menuNameArray[$activitylog['menuId']]) ? $menuNameArray[$activitylog['menuId']]['name'] : '';
                     }
                     if (in_array('username', $selectColumns)) {
                         $finalArray[$key]['username'] = isset($userNameArray[$activitylog['last_modifiedby']]) ? $userNameArray[$activitylog['last_modifiedby']]['userfullname'] : '';
                     }
                     if (in_array('empId', $selectColumns)) {
                         $finalArray[$key]['empId'] = isset($userNameArray[$activitylog['last_modifiedby']]) ? $userNameArray[$activitylog['last_modifiedby']]['employeeId'] : '';
                     }
                     if (in_array('useraction', $selectColumns)) {
                         $finalArray[$key]['useraction'] = $action[$activitylog['user_action']];
                     }
                     if (in_array('modifieddate', $selectColumns)) {
                         $finalArray[$key]['modifieddate'] = sapp_Global::getDisplayDate($activitylog['last_modifieddate']);
                     }
                 }
             }
         } else {
             // with search values from form
             $searchQuery = '';
             if ($this->_request->getParam('menu') != '') {
                 $searchQuery .= ' menuId =' . intval($this->_request->getParam('menu')) . ' AND';
             }
             if ($this->_request->getParam('useraction') != '') {
                 $searchQuery .= ' user_action =' . intval($this->_request->getParam('useraction')) . ' AND';
             }
             if ($this->_request->getParam('hiddenusername') != '') {
                 $username = $this->_request->getParam('hiddenusername');
                 //userid in request
                 $searchQuery .= ' log_details Like \'%"userid":"' . $username . '"%\' AND';
             }
             if ($this->_request->getParam('modifieddate') != '') {
                 $date = sapp_Global::change_date($this->_request->getParam('modifieddate'), 'database');
                 $date1 = str_replace('-', '/', $date);
                 $onedayafter = date('Y-m-d', strtotime($date1 . "+1 days"));
                 $onedaybefore = date('Y-m-d', strtotime($date1 . "-1 days"));
                 $searchQuery .= '(log_details Like "%' . $onedaybefore . '%" or log_details Like "%' . $date . '%" or log_details Like "%' . $onedayafter . '%")';
             }
             if ($searchQuery != '') {
                 $searchQuery = rtrim($searchQuery, " AND");
             }
             $activityLogData = $logmanager_model->getLogManagerDataReport('last_modifieddate', 'Desc', '', '', $searchQuery, array('*'));
             /*looping jsonlogs */
             if (count($activityLogData) > 0) {
                 $userArray = array();
                 $menuArray = array();
                 $logJsonArray = array();
                 $jsonCount = 0;
                 $index = 0;
                 foreach ($activityLogData as $activitylog) {
                     $logdetails = '{"testjson":[' . $activitylog['log_details'] . ']}';
                     $logarr = @get_object_vars(json_decode($logdetails));
                     if (!empty($logarr)) {
                         $logarr['testjson'] = array_reverse($logarr['testjson']);
                         $jsonCount = count($logarr['testjson']);
                     }
                     if ($jsonCount > 0 && isset($logarr['testjson']) && !empty($logarr['testjson'])) {
                         foreach ($logarr['testjson'] as $key => $curr) {
                             $currArray = @get_object_vars($curr);
                             /*userid and date check with form and json values*/
                             $flag = false;
                             if ($this->_request->getParam('modifieddate') != '') {
                                 $currArrayTemp = sapp_Global::getGMTformatdate($currArray['date']);
                                 $pos = strpos($currArrayTemp, $date);
                                 $flag = $pos !== false ? false : true;
                             }
                             if ($this->_request->getParam('hiddenusername') != '' && $username != $currArray['userid'] || $flag) {
                                 continue;
                             }
                             /*end userid and date check*/
                             $logJsonArray[$index]['userid'] = $currArray['userid'] != '' ? $currArray['userid'] : 1;
                             $logJsonArray[$index]['date'] = $currArray['date'];
                             $datesort[$index] = $currArray['date'];
                             // to sort by date
                             if (!in_array($currArray['userid'], $userArray)) {
                                 array_push($userArray, $currArray['userid']);
                             }
                             if (isset($activitylog['menuId'])) {
                                 if (!in_array($activitylog['menuId'], $menuArray)) {
                                     array_push($menuArray, $activitylog['menuId']);
                                 }
                             }
                             $logJsonArray[$index]['menu'] = $activitylog['menuId'];
                             $logJsonArray[$index]['action'] = $action[(string) $activitylog['user_action']];
                             $actionsort[$index] = $action[(string) $activitylog['user_action']];
                             $index++;
                         }
                     }
                 }
                 $menuNameArray = $activitylog_model->getMenuNamesByIds($menuArray);
                 $userNameArray = $activitylog_model->getuserNamesByIds($userArray);
                 $lastpage = ceil(count($logJsonArray) / $perPage);
                 $endIndex = intval($perPage);
                 if ($pageNo != 1) {
                     $startIndex = (intval($pageNo) - 1) * intval($perPage);
                 } else {
                     $startIndex = 0;
                 }
                 if (count($logJsonArray) > 0) {
                     if ($this->_request->getParam('sortby') != '') {
                         $sortby = $this->_request->getParam('sortby');
                         $order = $this->_request->getParam('order');
                         $orderby = $order == 'asc' ? SORT_ASC : SORT_DESC;
                         if ($sortby == 'user_action' || $sortby == 'last_modifieddate') {
                             // can sort by logJsonArray
                             if ($sortby == 'user_action') {
                                 array_multisort($actionsort, $orderby, $logJsonArray);
                             }
                             if ($sortby == 'last_modifieddate') {
                                 array_multisort($datesort, $orderby, $logJsonArray);
                             }
                             /* only perpage no of rows */
                             $splitArray = array_slice($logJsonArray, $startIndex, $endIndex);
                             foreach ($splitArray as $key => $logjson) {
                                 if (in_array('menuname', $selectColumns)) {
                                     $finalArray[$key]['menuname'] = isset($menuNameArray[(string) $logjson['menu']]) ? $menuNameArray[(string) $logjson['menu']]['name'] : '';
                                 }
                                 if (in_array('username', $selectColumns)) {
                                     $finalArray[$key]['username'] = isset($userNameArray[(string) $logjson['userid']]) ? $userNameArray[(string) $logjson['userid']]['userfullname'] : '';
                                 }
                                 if (in_array('empId', $selectColumns)) {
                                     $finalArray[$key]['empId'] = isset($userNameArray[(string) $logjson['userid']]) ? $userNameArray[(string) $logjson['userid']]['employeeId'] : '';
                                 }
                                 if (in_array('useraction', $selectColumns)) {
                                     $finalArray[$key]['useraction'] = $logjson['action'];
                                 }
                                 if (in_array('modifieddate', $selectColumns)) {
                                     $finalArray[$key]['modifieddate'] = sapp_Global::getDisplayDate($logjson['date']);
                                 }
                             }
                         } else {
                             $totalArray = array();
                             foreach ($logJsonArray as $key => $logjson) {
                                 if (in_array('menuname', $selectColumns)) {
                                     $totalArray[$key]['menuname'] = isset($menuNameArray[(string) $logjson['menu']]) ? $menuNameArray[(string) $logjson['menu']]['name'] : '';
                                 }
                                 $menunameSort[$key] = $totalArray[$key]['menuname'];
                                 if (in_array('username', $selectColumns)) {
                                     $totalArray[$key]['username'] = isset($userNameArray[(string) $logjson['userid']]) ? $userNameArray[(string) $logjson['userid']]['userfullname'] : '';
                                 }
                                 $usernameSort[$key] = $totalArray[$key]['username'];
                                 if (in_array('empId', $selectColumns)) {
                                     $totalArray[$key]['empId'] = isset($userNameArray[(string) $logjson['userid']]) ? $userNameArray[(string) $logjson['userid']]['employeeId'] : '';
                                 }
                                 $empIdSort[$key] = $totalArray[$key]['empId'];
                                 if (in_array('useraction', $selectColumns)) {
                                     $totalArray[$key]['useraction'] = $logjson['action'];
                                 }
                                 if (in_array('modifieddate', $selectColumns)) {
                                     $totalArray[$key]['modifieddate'] = sapp_Global::getDisplayDate($logjson['date']);
                                 }
                             }
                             if ($sortby == 'userfullname') {
                                 array_multisort($usernameSort, $orderby, $totalArray);
                             }
                             if ($sortby == 'employeeId') {
                                 array_multisort($empIdSort, $orderby, $totalArray);
                             }
                             if ($sortby == 'menuname') {
                                 array_multisort($menunameSort, $orderby, $totalArray);
                             }
                             /* only perpage no of rows */
                             if (count($totalArray) >= intval($perPage)) {
                                 $finalArray = array_slice($totalArray, $startIndex, $endIndex);
                             } else {
                                 $finalArray = $totalArray;
                             }
                         }
                     }
                 }
             }
         }
         if ($this->getRequest()->getPost()) {
             // To generate PDF START
             if ($this->_request->getParam('generatereport') == 'pdf') {
                 $this->generateActivityLogPdf($finalArray, $selectColumns);
             }
         }
         if ($this->_request->getParam('generatereport') == 'xcel') {
             //xcel generation
             foreach ($selectFields as $key => $val) {
                 foreach ($selectColumns as $column) {
                     if ($column == $key) {
                         $selectColumnLabels[$key] = $val;
                     }
                 }
             }
             sapp_Global::export_to_excel($finalArray, $selectColumnLabels, 'Activitylog Report.xlsx');
             exit;
         }
         $activitylogreport_form = new Default_Form_activitylogreport();
         $this->view->form = $activitylogreport_form;
         $this->view->totalselectfields = $selectFields;
         $this->view->tabkeys = implode(',', $selectColumns);
         $this->view->activitylogData = $finalArray;
         $this->view->pageNo = $pageNo;
         $this->view->perPage = $perPage;
         $this->view->sortBy = $sortby;
         $this->view->order = $order;
         $this->view->lastPageNo = $lastpage;
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }