public function pjActionDownload()
 {
     $this->setAjax(true);
     if ($this->isLoged() && $this->isAdmin()) {
         if (isset($_GET['id']) && !empty($_GET['id'])) {
             $id = basename($_GET['id']);
             $file = PJ_WEB_PATH . 'backup/' . $id;
             $buffer = "";
             @clearstatcache();
             if (is_file($file)) {
                 $handle = @fopen($file, "rb");
                 if ($handle) {
                     while (!feof($handle)) {
                         $buffer .= fgets($handle, 4096);
                     }
                     fclose($handle);
                 }
                 pjToolkit::download($buffer, $id);
             }
             die("File not found.");
         }
         die("Missing or empty parameters.");
     }
     $this->checkLogin();
     exit;
 }
 public function pjActionExport()
 {
     $this->setAjax(true);
     $this->setLayout('pjActionEmpty');
     if (isset($_POST['export']) && isset($_POST['separator']) && $this->isLoged() && $this->isAdmin()) {
         @set_time_limit(600);
         //10 min
         $name = 'pjLocale-' . time();
         $AppModel = pjAppModel::factory();
         $pjFieldModel = pjFieldModel::factory();
         $pjMultiLangModel = pjMultiLangModel::factory();
         $locale_arr = pjLocaleModel::factory()->select('t1.*, t2.title')->join('pjLocaleLanguage', 't2.iso=t1.language_iso')->orderBy('t1.sort ASC')->findAll()->getDataPair('id');
         if (empty($locale_arr)) {
             exit;
         }
         $multi_lang_arr = $pjMultiLangModel->select('t1.locale, t1.content, t2.id, t2.key')->join('pjField', 't2.id=t1.foreign_id', 'left outer')->where('t1.model', 'pjField')->where('t1.field', 'title')->whereIn('t1.locale', array_keys($locale_arr))->where('t1.source !=', 'data')->findAll()->getData();
         if (empty($multi_lang_arr)) {
             exit;
         }
         $export_arr = array();
         foreach ($multi_lang_arr as $k => $item) {
             if (!isset($export_arr[$item['id']])) {
                 $export_arr[$item['id']] = array('key' => $item['key'], 'locales' => array());
             }
             $export_arr[$item['id']]['locales'][$item['locale']] = $item['content'];
         }
         $csv = array();
         $separators = array('comma' => ",", 'semicolon' => ";", 'tab' => "\t");
         $separator = $separators[$_POST['separator']];
         $header = array('id', 'key');
         foreach ($locale_arr as $id => $data) {
             $header[] = $id . '::' . $data['title'];
         }
         $csv[] = join($separator, $header);
         foreach ($export_arr as $id => $data) {
             $cells = array();
             $cells[] = '"' . (int) $id . '"';
             $cells[] = '"' . str_replace(array("\r\n", "\n", "\t", '"'), array('\\n', '\\n', '\\t', '""'), $data['key']) . '"';
             foreach ($locale_arr as $locale_id => $item) {
                 if (isset($data['locales'][$locale_id])) {
                     $cells[] = '"' . str_replace(array("\r\n", "\n", "\t", '"'), array('\\n', '\\n', '\\t', '""'), $data['locales'][$locale_id]) . '"';
                 } else {
                     $cells[] = '""';
                 }
             }
             $csv[] = "\n";
             $csv[] = join($separator, $cells);
         }
         $content = join("", $csv);
         pjToolkit::download($content, $name . '.csv');
     }
     exit;
 }
 /**
  * Force browser to download the data as file
  *
  * @access public
  * @return void
  */
 public function download()
 {
     pjToolkit::download($this->data, $this->name, $this->mimeType);
 }
 /**
  * Force browser to download the data as file
  *
  * @access public
  * @return void
  */
 public function download()
 {
     pjToolkit::download($this->data, $this->name, 'text/csv');
 }