/**
  * Get page info by id.
  *
  * Example requeset: /admin/ajax/page-info
  */
 public function pageInfoAction()
 {
     $ids = $this->_request->getParam('id');
     if (!is_array($ids) || empty($ids)) {
         $this->_responseErrorString = 'Invalid ids';
         $this->_sendAjaxResponse();
     }
     $infos = array();
     foreach ($ids as $_id) {
         // It is the page id that is passed in
         $_pageId = Repo_Page::getInstance()->getIdByPageId($_id);
         $_object = new Object_Page($_pageId);
         if (!$_object->getId()) {
             continue;
         }
         $_info = array('id' => $_id, 'name' => $_object->name, 'description' => $_object->internal_desc ? $_object->internal_desc : '');
         $infos[] = $_info;
     }
     $this->_responseArray = array('pages' => $infos);
     $this->_sendAjaxResponse();
 }
 /**
  * Result detail page: view all results for selected survey/question.
  */
 public function resultDetailAction()
 {
     //if export to excel button was selected
     if ($this->_request->getParam('export')) {
         $this->view->exporting = $this->_request->getParam('export');
         if ($this->_request->getParam('export') == "students") {
             if ($this->_request->getParam('studentprintfields')) {
                 $this->view->studentprintfields = $this->_request->getParam('studentprintfields');
             }
         }
     }
     $id = $this->_request->getParam('id');
     $page = new Object_Page($id);
     $pageId = $page->getId();
     $clientId = $this->_request->getParam('client');
     $fromDate = $toDate = "";
     //if range calendar was changed
     if ($this->_request->isPost()) {
         $fromDate = $this->_request->getParam('input-filter-date-from');
         $toDate = $this->_request->getParam('input-filter-date-to');
         $this->view->currentTab = $this->_request->getParam('current-tab');
     } else {
         $this->view->currentTab = "#averages";
     }
     if (empty($pageId)) {
         // if no page id, may be a survey id
         // $this->_request->getParam('survey');
         // code here if a survey id has been passed
         // No page defined, redirect to result page
         $this->_redirect('/admin/client/result');
         return false;
     } else {
         // ** CE Student Quizzes code ****
         if ($fromDate == "" && $toDate == "") {
             //if no dates were posted, create
             $toDate = date('Y-m-d');
             //add 1 day
             $toDate = date('Y-m-d', strtotime('+1 day', strtotime($toDate)));
             $courseBegin = Repo_UserSurvey::getInstance()->getDateOfFirstQuizCompletion($pageId);
             if ($courseBegin) {
                 if (strtotime($courseBegin) >= strtotime($toDate)) {
                     $courseBegin = date('Y-m-d', strtotime('-1 day', strtotime($courseBegin)));
                 }
             }
             //if no quizzes completed yet, default to one week
             $fromDate = is_null($courseBegin) ? date('Y-m-d', strtotime('-1 week', strtotime($toDate))) : $courseBegin;
         }
         $this->view->quizLayout = true;
         $this->view->dateRange = array($fromDate, $toDate);
         $pageType = Repo_Page::getInstance()->getPageType($pageId);
         $this->view->pageType = $pageType;
         //collect statistics according to page type
         switch ($pageType) {
             case "survey":
                 //Tab 1 data: Totals and averages
                 $quizResultsGeneral = Repo_UserSurvey::getInstance()->getResultsQuizGeneral($pageId, $fromDate, $toDate);
                 $this->view->quizResultsGeneral = $quizResultsGeneral;
                 //Tab 2 data: Question data
                 $quizResultsQuestion = Repo_UserSurvey::getInstance()->getResultsQuizQuestions($pageId, $fromDate, $toDate);
                 $this->view->quizResultsQuestion = $quizResultsQuestion;
                 //Tab 3 data: Student details
                 $quizResultsStudent = Repo_UserSurvey::getInstance()->getStudentQuizProgress($pageId, $fromDate, $toDate);
                 $this->view->quizResultsStudent = $quizResultsStudent;
                 break;
             case "cefeedback":
                 $this->view->currentTab = "#cefeedback";
                 //Get Question Type:
                 $feedbackData = Repo_UserSurvey::getInstance()->getResultsCEFeedback($pageId, $fromDate, $toDate);
                 //Tab 1 data: feedback results
                 $this->view->CEFeedback = $feedbackData[1];
                 $this->view->CEFeedbackRespondents = $feedbackData[0];
                 break;
         }
     }
     if ($clientId > 0) {
         $client = new Object_Client($clientId);
         $this->view->clientName = $client->name;
     }
     $this->view->page = $page;
 }
 /**
  * Generate pages based on the language folder.
  *
  * @param string $folderPath
  * @param string $language
  * @return false array
  */
 protected function _generatePagesForLanguageFolder($folderPath, $language)
 {
     $pages = array();
     $dir = dir($folderPath);
     while (false !== ($entry = $dir->read())) {
         if ($entry == '.' || $entry == '..' || $entry == '.DS_Store') {
             continue;
         }
         // We deal with each page
         $_pageFolder = $folderPath . DS . $entry;
         $_pageId = $entry;
         $_id = (int) Repo_Page::getInstance()->addNew($this->_currentClientId, $_pageId, Repo_Page::PAGE_TYPE_STATIC, Repo_Page::PAGE_STATUS_IN_PROGRESS, '', false, false, false, false, $language, $_pageId, false);
         if (empty($_id)) {
             // OK, we are deal with existing page
             $_id = Repo_Page::getInstance()->clientPageExists($this->_currentClientId, $_pageId, $language);
             $_existingPage = new Object_Page($_id);
             $_existingPage->cloud_file_container = null;
             $_existingPage->version++;
             $_existingPage->save();
         }
         // Copy to a path
         $_pageStorageFolder = $this->getClientFolderPath($this->_currentClientId) . DS . self::getPageFolderName($_pageId);
         if (!file_exists($_pageStorageFolder)) {
             mkdir($_pageStorageFolder, 0777);
         } else {
             // Remove the existing content since we are updating.
             if (file_exists($_pageStorageFolder . DS . $_pageId)) {
                 Functions_File::rrmdir($_pageStorageFolder . DS . $_pageId);
             }
         }
         Functions_File::recurse_copy($_pageFolder, $_pageStorageFolder . DS . $_pageId);
         // Check whether successfully
         if (!file_exists($_pageStorageFolder . DS . $_pageId)) {
             throw new Zend_Exception('Can not copy page content from a zip file: ' . $_pageStorageFolder);
         }
         $pages[] = $_id;
         // In case we upload a thumb image, use it.
         $page = new Object_Page($_id);
         $page->useStaticThumb();
     }
     $dir->close();
     return $pages;
 }
 /**
  * Generate pages based on the language folder.
  *
  * @param string $folderPath
  * @param string $language
  * @return false array
  */
 protected function _generatePagesForLanguageFolder($folderPath, $language)
 {
     // Set client id
     Manager_File_Rackspace::getInstance()->setClientId($this->_currentClientId);
     $pages = array();
     $dir = dir($folderPath);
     while (false !== ($entry = $dir->read())) {
         if ($entry == '.' || $entry == '..' || $entry == '.DS_Store') {
             continue;
         }
         // We deal with each page
         $_pageFolder = $folderPath . DS . $entry;
         $_pageId = $entry;
         $_id = (int) Repo_Page::getInstance()->addNew($this->_currentClientId, $_pageId, Repo_Page::PAGE_TYPE_STATIC, Repo_Page::PAGE_STATUS_IN_PROGRESS, '', false, false, false, false, $language, $_pageId, Manager_File_Rackspace::getInstance()->getGeneralContainer());
         if (empty($_id)) {
             // OK, we are deal with existing page
             $_id = Repo_Page::getInstance()->clientPageExists($this->_currentClientId, $_pageId, $language);
             $_existingPage = new Object_Page($_id);
             $_existingPage->version++;
             $_existingPage->cloud_file_container = Manager_File_Rackspace::getInstance()->getGeneralContainer();
             $_existingPage->save();
         }
         // Copy to a path
         $_pageStorageFolder = $this->getClientFolderPath($this->_currentClientId) . self::PS . parent::getPageFolderName($_pageId);
         // Cleanup first
         Manager_File_Rackspace::getInstance()->deletePeudoFolder($_pageStorageFolder);
         // Store
         Functions_File::recurse_copy_cloud($_pageFolder, $_pageStorageFolder . self::PS . $_pageId);
         // Check whether successfully
         $pages[] = $_id;
         // In case we upload a thumb image, use it.
         $page = new Object_Page($_id);
         $page->useStaticThumb();
     }
     $dir->close();
     return $pages;
 }