Exemplo n.º 1
0
 /**
  * Сохраняем документ на сайте.
  * 
  * @return \CFile
  */
 public function saveFile()
 {
     $login = '******';
     $content = $this->getOutput();
     $file = new CFile();
     $file->path = 'users/' . substr($login, 0, 2) . "/{$login}/upload/";
     $file->name = basename($file->secure_tmpname($file->path, '.odt'));
     $file->size = strlen($content);
     if ($file->putContent($file->path . $file->name, $content)) {
         return $file;
     }
 }
Exemplo n.º 2
0
 /**
  * Обработка и оплата операций
  * 
  * @global type $DB
  * @param type $option
  * @return boolean 
  */
 function billingOperation($option, $transaction_id)
 {
     global $DB;
     $ok = false;
     $account = new account();
     switch ($option['op_code']) {
         // Аккаунт ПРО у фрилансера
         case 48:
         case 49:
         case 50:
         case 51:
         case 76:
             // Удаляем операции по покупке ответов - публикуем ответы
             $prof = new payed();
             $ok = $prof->SetOrderedTarif($this->uid, $transaction_id, 1, "Аккаунт PRO", $option['op_code'], $error);
             if ($ok) {
                 $_SESSION['pro_last'] = payed::ProLast($_SESSION['login']);
                 $_SESSION['pro_last'] = $_SESSION['pro_last']['freeze_to'] ? false : $_SESSION['pro_last']['cnt'];
                 $userdata = new users();
                 $_SESSION['pro_test'] = $userdata->GetField($this->uid, $error2, 'is_pro_test', false);
                 $this->clearBlockedOperations(step_freelancer::OFFERS_OP_CODE);
                 $step_frl = new step_freelancer();
                 $offers = $step_frl->getWizardOffers($this->uid, 'all', false);
                 if ($offers) {
                     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/users.php";
                     $step_frl->log = $this->log;
                     $step_frl->user = new users();
                     $step_frl->user->GetUserByUID($this->uid);
                     $step_frl->transferOffers($offers);
                 }
                 $this->showProjectsFeedbacks();
             }
             break;
             // Аккаунт ПРО у работодателя
         // Аккаунт ПРО у работодателя
         case 15:
             $prof = new payed();
             $ok = $prof->SetOrderedTarif($this->uid, $transaction_id, 1, "Аккаунт PRO", $option['op_code'], $error);
             if ($ok) {
                 $_SESSION['pro_last'] = payed::ProLast($_SESSION['login']);
                 $_SESSION['pro_last'] = $_SESSION['pro_last']['freeze_to'] ? false : $_SESSION['pro_last']['cnt'];
                 $userdata = new users();
                 $_SESSION['pro_test'] = $userdata->GetField($this->uid, $error2, 'is_pro_test', false);
             }
             // Обновляем выбор цвета для проектов тк он для ПРО бесплатный
             $colorProjects = $this->updateColorProject();
             $prj = new new_projects();
             foreach ($colorProjects as $k => $project) {
                 $delete_color[] = $project['op_id'];
                 if ($project['country'] == null) {
                     $project['country'] = 'null';
                 }
                 if ($project['city'] == null) {
                     $project['city'] = 'null';
                 }
                 $project['name'] = addslashes($project['name']);
                 $project['descr'] = addslashes($project['descr']);
                 if ($project['logo_id'] <= 0) {
                     $project['logo_id'] = 'null';
                 }
                 $project['payed_items'] = $project['payed_items'] | '010';
                 $project['is_color'] = 't';
                 $prj->editPrj($project, false);
             }
             // Удаляем данные операции
             if ($delete_color) {
                 $this->deleteDraftAccountOperation($delete_color);
             }
             break;
             // Публикация конкурса
         // Публикация конкурса
         case new_projects::OPCODE_KON:
         case new_projects::OPCODE_KON_NOPRO:
             require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/wizard/step_wizard_registration.php';
             $drafts = new drafts();
             $draft = $drafts->getDraft($option['parent_id'], $this->uid, 1);
             // Если еще не опубликован
             if (!$draft['prj_id']) {
                 $project_id = $draft['id'];
                 $error = $account->Buy($bill_id, $transaction_id, $option['op_code'], $this->uid, $option['descr'], $option['comment'], 1, 0);
                 $ok = $bill_id > 0;
                 if ($bill_id) {
                     $color = $DB->val("SELECT id FROM draft_account_operations WHERE parent_id = ? AND op_type = 'contest' AND option = 'color' AND uid = ?", $project_id, wizard::getUserIDReg());
                     $draft['billing_id'] = $bill_id;
                     $draft['folder_id'] = 'null';
                     $draft['payed'] = '0';
                     $draft['payed_items'] = '000';
                     if (is_pro() && $color > 0) {
                         $draft['is_color'] = 't';
                     } else {
                         $draft['is_color'] = 'f';
                     }
                     $draft['win_date'] = date('d-m-Y', strtotime($draft['win_date']));
                     $draft['end_date'] = date('d-m-Y', strtotime($draft['end_date']));
                     $draft['is_bold'] = 'f';
                     $draft['user_id'] = $this->uid;
                     if ($draft['country'] == null) {
                         $draft['country'] = 'null';
                     }
                     if ($draft['city'] == null) {
                         $draft['city'] = 'null';
                     }
                     $draft['name'] = addslashes($draft['name']);
                     $draft['descr'] = addslashes($draft['descr']);
                     if ($draft['logo_id'] <= 0) {
                         $draft['logo_id'] = 'null';
                     }
                     $prj = new new_projects();
                     $attachedfiles_tmpdraft_files = drafts::getAttachedFiles($option['parent_id'], 4);
                     if ($attachedfiles_tmpdraft_files) {
                         $attachedfiles_tmpdraft_files = array_map(create_function('$a', 'return array("id" => $a);'), $attachedfiles_tmpdraft_files);
                     }
                     if ($attachedfiles_tmpdraft_files) {
                         $month = date('Ym');
                         $dir = 'projects/upload/' . $month . '/';
                         $files = step_wizard_registration::transferFiles($attachedfiles_tmpdraft_files, 'file_projects', $dir);
                     }
                     $spec = $draft["categories"];
                     $spec = explode("|", $spec);
                     $spec = array(array('category_id' => $spec[0], 'subcategory_id' => $spec[1]));
                     $prj->addPrj($draft, $files);
                     $prj->saveSpecs($draft["id"], $spec);
                     // смотрим были ли выбраны платные опции для опубликованного конкурса
                     if ($draft['id'] != $project_id && $draft['id'] > 0) {
                         if ($this->sleep[$project_id]) {
                             foreach ($this->sleep[$project_id] as $k => $opt) {
                                 $opt['parent_id'] = $draft['id'];
                                 $this->billingOperation($opt);
                             }
                         } else {
                             //Обновляем родителя на всякий случай
                             $update = array("parent_id" => $draft['id']);
                             $DB->update("draft_account_operations", $update, "parent_id = ? AND op_type = 'contest' AND uid = ?", $project_id, wizard::getUserIDReg());
                             $this->sleep_parent[$project_id] = $draft['id'];
                         }
                         $DB->update("draft_projects", array('prj_id' => $draft['id']), "id = ? AND uid = ?", $project_id, wizard::getUserIDReg());
                     }
                 }
             }
             break;
             // Платный проект/конкурс
         // Платный проект/конкурс
         case 53:
             $prj = new new_projects();
             if ($this->sleep_parent[$option['parent_id']]) {
                 $option['parent_id'] = $this->sleep_parent[$option['parent_id']];
             }
             $project = $prj->getProject($option['parent_id']);
             if (!$project['id']) {
                 $this->sleep[$option['parent_id']][$option['id']] = $option;
                 return true;
             } else {
                 unset($this->sleep[$option['parent_id']]);
             }
             if ($project['country'] == null) {
                 $project['country'] = 'null';
             }
             if ($project['city'] == null) {
                 $project['city'] = 'null';
             }
             $project['name'] = addslashes($project['name']);
             $project['descr'] = addslashes($project['descr']);
             if ($project['logo_id'] <= 0) {
                 $project['logo_id'] = 'null';
             }
             $project['folder_id'] = 'null';
             $items = array();
             switch ($option['option']) {
                 case 'top':
                     $project['top_days'] = $option['op_count'];
                     break;
                 case 'color':
                     $is_pay = $project['payed_items'] & '010';
                     if ($is_pay != '010') {
                         $project['payed_items'] = $project['payed_items'] | '010';
                         $project['is_color'] = 't';
                         $items['color'] = true;
                         if (is_pro()) {
                             $is_payed = true;
                             $prj->SavePayedInfo($items, $project['id'], null, $project['top_days']);
                             $prj->editPrj($project, false);
                         }
                     } else {
                         $is_payed = true;
                     }
                     break;
                 case 'bold':
                     $is_pay = $project['payed_items'] & '001';
                     if ($is_pay != '001') {
                         $project['payed_items'] = $project['payed_items'] | '001';
                         $project['is_bold'] = 't';
                         $items['bold'] = true;
                     } else {
                         $is_payed = true;
                     }
                     break;
                 case 'logo':
                     $is_pay = $project['payed_items'] & '100';
                     if ($is_pay != '100') {
                         $key = md5(microtime());
                         $prj = new tmp_project($key);
                         $prj->init(1);
                         $fu = new CFile($option['src_id']);
                         $ext = $fu->getext();
                         $tmp_dir = $prj->getDstAbsDir();
                         $tmp_name = $fu->secure_tmpname($tmp_dir, '.' . $ext);
                         $tmp_name = substr_replace($tmp_name, "", 0, strlen($tmp_dir));
                         $fu->table = 'file_projects';
                         $r = $fu->_remoteCopy($tmp_dir . $tmp_name);
                         $project['payed_items'] = $project['payed_items'] | '100';
                         $project['logo_id'] = $fu->id;
                         $items['logo'] = true;
                         if ($option['extra']) {
                             $project['link'] = $option['extra'];
                         }
                     } else {
                         $is_payed = true;
                     }
                     break;
             }
             if (!$is_payed) {
                 $error = $account->Buy($bill_id, $transaction_id, $option['op_code'], $this->uid, $option['descr'], $option['comment'], $option['ammount'], 0);
                 $ok = $bill_id > 0;
                 $project['billing_id'] = $bill_id;
                 $prj->SavePayedInfo($items, $project['id'], $bill_id, $project['top_days']);
                 $prj->editPrj($project, false);
             } else {
                 $ok = true;
             }
             break;
             // Платные ответы на проекты
         // Платные ответы на проекты
         case 61:
             $answers = new projects_offers_answers();
             $error = $answers->BuyByFM($this->uid, $option['op_count'], $transaction_id, 0);
             if (!$error) {
                 $ok = true;
                 $_SESSION['answers_ammount'] = $option['op_count'];
                 // Публикуем ответы
                 $step_frl = new step_freelancer();
                 $offers = $step_frl->getWizardOffers($this->uid, $option['op_count']);
                 if ($offers) {
                     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/users.php";
                     $step_frl->log = $this->log;
                     $step_frl->user = new users();
                     $step_frl->user->GetUserByUID($this->uid);
                     $step_frl->transferOffers($offers);
                 }
             }
             break;
     }
     return $ok;
 }
Exemplo n.º 3
0
 $path = __paramInit("string", null, "path");
 $path = trim($path, '/');
 $info = '';
 $old_link = '';
 $rename_name = '';
 $name = '';
 $link = '';
 $error_folder = '';
 $cf = new CFile($_FILES['document'], dav_file_upload::FILE_TABLE);
 if ($cf->CheckPath($path)) {
     $destname = dav_file_upload_createDestName($cf);
     //check existing file
     $existingFile = new CFile("{$path}/{$destname}");
     if ($existingFile->id > 0) {
         $ext = $existingFile->getext($existingFile->name);
         $tmp = $existingFile->secure_tmpname($path . '/', '.' . $ext);
         $rename_name = substr_replace($tmp, "", 0, strlen($path) + 1);
         $s = preg_replace("#\\." . $ext . "\$#", "", $destname);
         $length = strlen($s . '_' . $rename_name);
         if ($length > 64 && strlen($rename_name) < 64) {
             $s = substr($s, 0, 63 - strlen($rename_name));
             $rename_name = $s . "_" . $rename_name;
         }
         $existingFile->Rename("{$path}/{$rename_name}");
         $info = 'Файл был заменен';
         $old_link = WDCPREFIX . '/' . $path . '/' . $rename_name;
     }
     $cf->server_root = 1;
     $cf->max_size = dav_file_upload::MAX_FILE_SIZE;
     $cf->MoveUploadedFile($path . '/', true, $destname);
     $err = is_string($cf->error[0]) ? $cf->error : $cf->error[0];
Exemplo n.º 4
0
 /**
  * Редактирование личного сообщения.
  * 
  * @param int    $from_id            UID пользователя-отправителя 
  * @param int    $modified_id        UID пользователя изменявшего сообщение
  * @param int    $id                 ID сообщения
  * @param string $msg_text           текст сообщения
  * @param array  $attachedfiles_file приаттаченные файлы
  * @param string $modified_reason    причина редактирования
  *
  * @return bool true - успех, false - провал
  */
 public function Update($from_id = 0, $modified_id = 0, $id = 0, $msg_text = '', $attachedfiles_file = array(), $modified_reason = '')
 {
     $bRet = false;
     if ($from_id && $id && $msg_text) {
         require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/users.php';
         $users = new users();
         $login = $users->GetName($from_id, $err);
         $files = array();
         if ($login) {
             if ($attachedfiles_file) {
                 foreach ($attachedfiles_file as $file) {
                     switch ($file['status']) {
                         case 1:
                             // добавляем файл
                             $cFile = new CFile($file['id']);
                             $cFile->table = 'file';
                             $ext = $cFile->getext();
                             $tmp_dir = 'users/' . substr($login['login'], 0, 2) . '/' . $login['login'] . '/contacts/';
                             $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext);
                             $tmp_name = substr_replace($tmp_name, '', 0, strlen($tmp_dir));
                             $cFile->_remoteCopy($tmp_dir . $tmp_name, true);
                             $files[] = $cFile->id;
                             break;
                         case 3:
                             // ранее добавленный
                             $files[] = $file['id'];
                             break;
                         case 4:
                             // удаляем файл
                             $cFile = new CFile();
                             $cFile->Delete($file['id']);
                             break;
                     }
                 }
             }
             $DB = new DB();
             $DB->val('SELECT message_update(?i, ?i, ?, ?a, ?)', $id, $modified_id, $msg_text, $files, $modified_reason);
             $bRet = empty($DB->error);
         }
     }
     return $bRet;
 }
Exemplo n.º 5
0
 **/
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/CFile.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/dav_file_upload.php';
if (!hasPermissions('admin')) {
    header('Location: /404.php');
    exit;
}
$srcdir = $_SERVER['DOCUMENT_ROOT'] . '/about';
$ls = scandir($srcdir);
foreach ($ls as $item) {
    if ($item != '.' && $item !== '..' && !is_dir("{$srcdir}/{$item}")) {
        $filedata = array('name' => $item, 'tmp_name' => "{$srcdir}/{$item}", 'size' => filesize("{$srcdir}/{$item}"));
        $srcfile = new CFile($filedata);
        $srcfile->unlinkOff = true;
        $path = 'about/documents';
        $destfile = new CFile("{$path}/{$item}", dav_file_upload::FILE_TABLE);
        $rename_name = '';
        if ($destfile->id) {
            $ext = $destfile->getext($destfile->name);
            $tmp = $destfile->secure_tmpname($path . '/', '.' . $ext);
            $rename_name = substr_replace($tmp, '', 0, strlen($path) + 1);
            $destfile->Rename("{$path}/{$rename_name}");
        }
        $srcfile->server_root = 1;
        $srcfile->max_size = dav_file_upload::MAX_FILE_SIZE;
        $r = $srcfile->MoveUploadedFile($path . '/', true, $item);
        dav_file_upload::addRecord($srcfile->id, $srcfile->name, $rename_name);
        echo "Copy {$srcdir}/{$item} " . WDCPREFIX . '/' . $path . '/' . $item . '<br><br>';
    }
}
Exemplo n.º 6
0
 /**
  * Связывает файлы загруженные ассинхронно с проектом и добавляет информацию о них в массив $this->_attach
  *
  * @param   array     $files         Список добавляемых файлов
  * @param   boolean   $from_draft    Файлы из черновика
  */
 function addAttachedFiles($files, $from_draft = false)
 {
     global $DB;
     $old_files = array();
     if ($this->_attach) {
         foreach ($this->_attach as $f) {
             array_push($old_files, $f['file_id']);
         }
     }
     if ($from_draft) {
         if ($this->_attach) {
             foreach ($this->_attach as $attach_id => $attach) {
                 if (!in_array($attach['file_id'], $old_files)) {
                     $this->delAttach($attach_id, true);
                 }
             }
         }
     }
     if ($files) {
         foreach ($files as $file) {
             switch ($file['status']) {
                 case 4:
                     // Удаляем файл
                     if ($this->_attach) {
                         foreach ($this->_attach as $attach_id => $attach) {
                             if ($attach['file_id'] == $file['id']) {
                                 $this->delAttach($attach_id, true);
                             }
                         }
                     }
                     break;
                 case 1:
                 case 3:
                     // Добавляем файл
                     if (!in_array($file['id'], $old_files)) {
                         if (in_array($file['id'], $old_files)) {
                             $need_copy = false;
                         } else {
                             $need_copy = true;
                         }
                         $cFile = new CFile($file['id']);
                         $cFile->table = 'file_projects';
                         $ext = $cFile->getext();
                         if ($need_copy) {
                             $tmp_dir = $this->_tmpAbsDir;
                             $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext);
                             $tmp_name = substr_replace($tmp_name, "", 0, strlen($tmp_dir));
                             $cFile->_remoteCopy($tmp_dir . $tmp_name, true);
                         }
                         $this->_attach[] = array('file_id' => $cFile->id, 'path' => $cFile->path, 'name' => $cFile->name, 'size' => $cFile->size, 'ftype' => $cFile->getext(), 'is_new' => true);
                         $this->_tmpFiles[] = $cFile->name;
                     }
                     break;
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  *  Добавление/удаление файлов к рассылке
  * @param array   $files   Список файлов
  * @param integer $id      Ид рассылки
  */
 public function addAttachedFiles($files, $id)
 {
     if ($files) {
         foreach ($files as $file) {
             switch ($file['status']) {
                 case 4:
                     // Удаляем файл
                     $this->delAttach($file['id']);
                     break;
                 case 1:
                     // Добавляем файл
                     $cFile = new CFile($file['id']);
                     $cFile->table = 'file_mailer';
                     $ext = $cFile->getext();
                     $tmp_name = $cFile->secure_tmpname(self::FILE_DIR, '.' . $ext);
                     $tmp_name = substr_replace($tmp_name, "", 0, strlen(self::FILE_DIR));
                     $cFile->_remoteCopy(self::FILE_DIR . $tmp_name, true);
                     $this->insertAttachedFile($cFile->id, $id);
                     break;
             }
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Связывает файлы загруженные ассинхронно с комментарием
  *
  * @param  array $files Список загруженных файлов @see attachedfiles::getFiles
  * @param  string $login Логин пользователя
  * @param  integer $msg_id ID комментария
  * @return bool
  */
 function addAttachedFiles($files = array(), $msg_id = 0, $login = '')
 {
     global $DB;
     $model = $this->model();
     if (!isset($model['attaches'])) {
         return false;
     }
     if (!$login) {
         $login = $_SESSION['login'];
     }
     $sql = 'SELECT ' . $model['attaches']['fields']['file'] . ' AS fid FROM ' . $model['attaches']['table'] . ' WHERE ' . $model['attaches']['fields']['comment'] . ' = ?i AND ' . $model['attaches']['fields']['inline'] . ' != TRUE';
     $attaches = $DB->rows($sql, $msg_id);
     $old_files = array();
     if ($attaches) {
         foreach ($attaches as $f) {
             array_push($old_files, $f['fid']);
         }
     }
     $max_image_size = array('width' => 390, 'height' => 1000, 'less' => 0);
     if ($files) {
         $num = 0;
         foreach ($files as $file) {
             switch ($file['status']) {
                 case 4:
                     // Удаляем файл
                     $cFile = new CFile($file['id']);
                     $cFile->table = $model['attaches']['file_table'];
                     if ($cFile->id) {
                         $sql = 'DELETE FROM ' . $model['attaches']['table'] . ' WHERE ' . $model['attaches']['fields']['file'] . ' = ?i';
                         $DB->query($sql, $cFile->id);
                         $cFile->Delete($cFile->id);
                     }
                     break;
                 case 1:
                     $num++;
                     if (in_array($file['id'], $old_files)) {
                         $need_copy = false;
                     } else {
                         $need_copy = true;
                     }
                     // Добавляем файл
                     $cFile = new CFile($file['id']);
                     $cFile->proportional = 1;
                     $cFile->table = $model['attaches']['file_table'];
                     $ext = $cFile->getext();
                     if ($need_copy) {
                         $tmp_dir = 'users/' . substr($login, 0, 2) . '/' . $login . '/upload/';
                         $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext);
                         $tmp_name = substr_replace($tmp_name, '', 0, strlen($tmp_dir));
                         $cFile->_remoteCopy($tmp_dir . $tmp_name, true);
                     }
                     if (in_array($ext, $GLOBALS['graf_array'])) {
                         $is_image = TRUE;
                     } else {
                         $is_image = FALSE;
                     }
                     if ($is_image && $ext != 'swf' && $ext != 'flv') {
                         if ($cFile->image_size['width'] > $max_image_size['width'] || $cFile->image_size['height'] > $max_image_size['height']) {
                             if ($need_copy) {
                                 if ($cFile->resizeImage($cFile->path . 'sm_' . $cFile->name, $max_image_size['width'], $cFile->image_size['height'], 'landscape')) {
                                     $cFile->small = true;
                                 }
                             } else {
                                 $cFile->small = true;
                             }
                         } else {
                             $cFile->small = false;
                         }
                     } else {
                         $cFile->small = false;
                     }
                     $aData = array($model['attaches']['fields']['comment'] => $msg_id, $model['attaches']['fields']['file'] => $cFile->id);
                     if (isset($model['attaches']['fields']['small'])) {
                         $aData[$model['attaches']['fields']['small']] = $cFile->small;
                     }
                     if (isset($model['attaches']['fields']['sort'])) {
                         $aData[$model['attaches']['fields']['sort']] = $num;
                     }
                     $DB->insert($model['attaches']['table'], $aData);
                     break;
             }
         }
     }
     return true;
 }
Exemplo n.º 9
0
 /**
  * Сохраняет контент документа в файл.
  * 
  * @param string $content   текст файла.
  * @param string $ext   расширение файла.
  * @return CFile   загруженный файл.
  */
 function _saveDocFile($content, $ext = '.pdf')
 {
     if (trim($content) == "") {
         return NULL;
     }
     $file = new CFile();
     $file->table = 'file_sbr';
     $file->path = $this->getUploadDir();
     $file->name = basename($file->secure_tmpname($file->path, '.pdf'));
     $file->size = strlen($content);
     if ($file->putContent($file->path . $file->name, $content)) {
         return $file;
     }
     return NULL;
 }
Exemplo n.º 10
0
 /**
  * Генерация Exсel таблицы на основе шаблона 
  * 
  * @param type $cellnames - массив ячеек где искать шаблоны подстановки
  * @return boolean|\CFile
  */
 public function generateExcel($cellnames = array('A1'))
 {
     if (empty($cellnames) || empty($this->data)) {
         return false;
     }
     $objReader = PHPExcel_IOFactory::createReader('Excel5');
     $objPHPExcel = $objReader->load(ABS_PATH . $this->template_path . $this->template);
     $data = array();
     foreach ($this->data as $key => $value) {
         $value = iconv("windows-1251", "utf-8", $value);
         $data['{' . $key . '}'] = $value;
     }
     $keys = array_keys($data);
     $vals = array_values($data);
     foreach ($cellnames as $cellname) {
         $content = (string) $objPHPExcel->getActiveSheet()->getCell($cellname);
         if (!empty($content)) {
             $content = str_replace($keys, $vals, $content);
             $objPHPExcel->getActiveSheet()->setCellValue($cellname, $content);
         }
     }
     if (!file_exists($this->tmp_path)) {
         mkdir($this->tmp_path, 0777);
     }
     $tmpFilename = tempnam($this->tmp_path, 'tmp');
     //$tmpFilename = $this->tmp_path . substr(md5(microtime()), 0, 6) . '.xls';
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
     $objWriter->save($tmpFilename);
     $content = file_get_contents($tmpFilename);
     unlink($tmpFilename);
     $file = new CFile();
     $file->path = $this->getFilePath();
     $file->table = $this->file_table;
     $file->size = strlen($content);
     $file->src_id = $this->file_src_id;
     $file->name = basename($file->secure_tmpname($file->path, '.xls'));
     $file->original_name = change_q_x($this->file_original_name);
     if (!$file->putContent($file->path . $file->name, $content)) {
         return false;
     }
     Events::trigger('generate_file', $file);
     return $file;
 }
Exemplo n.º 11
0
 /**
  * НЕ ИСПОЛЬЗОВАТЬ - УСТАРЕЛ СМ generateInvoice2.
  * 
  * Генерация счета
  *
  * @todo: может перенести генерацию в очереди?
  * @todo: но тогда нужно организовать обратную связь.
  * 
  * @param type $user_info
  *
  * @return bool|\CFile
  */
 public function generateInvoice($user_info)
 {
     extract($this->options);
     $file = new CFile();
     $file_path = $this->getFilePath();
     $reserve_id = @$this->data['reserve_id'];
     if (!$file_path || !$reserve_id || empty($this->data)) {
         return false;
     }
     $data = $this->getCheckByReserveId($reserve_id);
     if (isset($data['payed_date']) && !empty($data['payed_date'])) {
         return false;
     }
     if (isset($data['check_file_id']) && $data['check_file_id'] > 0) {
         $file->Delete($data['check_file_id']);
     }
     if (!$data) {
         $data = array();
     }
     $this->data = array_merge($data, $this->data, $user_info);
     $data = $this->data;
     $bill_num = sprintf($bill_num_format, $data['reserve_id']);
     $data['bill_num'] = $bill_num;
     $data['date'] = date_text($data['date'], 'd');
     $data['price_txt'] = num2str(intval($data['price']));
     $data['price'] = number_format($data['price'], 2, ',', '');
     $data['title'] = sprintf($check_title, $bill_num);
     foreach ($data as $key => $value) {
         $data['$' . $key] = $value;
         unset($data[$key]);
     }
     $pdf = new odt2pdf($invoice_template);
     $pdf->setFolder(ABS_PATH . $templates_path);
     $pdf->convert($data);
     $content = $pdf->output(null, 'S');
     $len = strlen($content);
     if (!$len) {
         return false;
     }
     $file->path = $file_path;
     $file->table = $table_files;
     $file->size = $len;
     $file->src_id = $src_id;
     $file->name = basename($file->secure_tmpname($file->path, '.pdf'));
     $file->original_name = change_q_x(sprintf($check_org_filename, $bill_num));
     if (!$file->putContent($file->path . $file->name, $content)) {
         return false;
     }
     $this->data['check_file_id'] = $file->id;
     return $this->addCheck() ? $file : false;
 }
Exemplo n.º 12
0
 /**
  * Изменение документа
  *
  * @param    integer  $id      ID документа
  * @param    array    $data    Данные документа
  */
 function updateDocument($id, $data)
 {
     global $DB;
     if (!$data['letters_doc_frm_user_3_db_id'] || $data['letters_doc_frm_user_3_db_id'] == 'null') {
         $data['letters_doc_frm_user_3_db_id'] = null;
         $data['letters_doc_frm_user3_status_data'] = null;
         $data['letters_doc_frm_user3_status_date_data'] = null;
     }
     if (!$data['letters_doc_frm_user3_status_date_data']) {
         $data['letters_doc_frm_user3_status_date_data'] = null;
     }
     if (!$data['letters_doc_frm_user2_status_date_data']) {
         $data['letters_doc_frm_user2_status_date_data'] = null;
     }
     if (!$data['letters_doc_frm_user1_status_date_data']) {
         $data['letters_doc_frm_user1_status_date_data'] = null;
     }
     if (!$data['letters_doc_frm_user3_status_data']) {
         $data['letters_doc_frm_user3_status_data'] = null;
     }
     if (!$data['letters_doc_frm_user2_status_data']) {
         $data['letters_doc_frm_user2_status_data'] = null;
     }
     if (!$data['letters_doc_frm_user1_status_data']) {
         $data['letters_doc_frm_user1_status_data'] = null;
     }
     if (!$data['letters_doc_frm_parent_db_id'] || $data['letters_doc_frm_parent_db_id'] == 'null') {
         $data['letters_doc_frm_parent_db_id'] = null;
     }
     if (!$data['letters_doc_frm_group'] || $data['letters_doc_frm_group'] == 'null') {
         $data['letters_doc_frm_group'] = null;
     }
     if (!$data['letters_doc_frm_group_db_id'] || $data['letters_doc_frm_group_db_id'] == 'null') {
         $data['letters_doc_frm_group_db_id'] = null;
     }
     if (!$data['letters_doc_frm_group_db_id'] && !empty($data['letters_doc_frm_group'])) {
         $data['letters_doc_frm_group_db_id'] = letters::checkCreateGroup($data['letters_doc_frm_group']);
     }
     if ($data['letters_doc_frm_user_1_section'] == '1') {
         $data['letters_doc_frm_user_1_section'] = true;
     } else {
         $data['letters_doc_frm_user_1_section'] = false;
     }
     if ($data['letters_doc_frm_user_2_section'] == '1') {
         $data['letters_doc_frm_user_2_section'] = true;
     } else {
         $data['letters_doc_frm_user_2_section'] = false;
     }
     if ($data['letters_doc_frm_user_3_section'] == '1') {
         $data['letters_doc_frm_user_3_section'] = true;
     } else {
         $data['letters_doc_frm_user_3_section'] = false;
     }
     if ($data['letters_doc_frm_withoutourdoc'] == '1') {
         $data['letters_doc_frm_withoutourdoc'] = true;
     } else {
         $data['letters_doc_frm_withoutourdoc'] = false;
     }
     $doc = self::getDocument($id);
     $doc_data['title'] = $data['letters_doc_frm_title'];
     $doc_data['user_1'] = $data['letters_doc_frm_user_1_db_id'];
     $doc_data['user_2'] = $data['letters_doc_frm_user_2_db_id'];
     $doc_data['user_3'] = $data['letters_doc_frm_user_3_db_id'];
     $doc_data['group_id'] = $data['letters_doc_frm_group_db_id'];
     $doc_data['parent'] = $data['letters_doc_frm_parent_db_id'];
     $doc_data['user_status_1'] = $data['letters_doc_frm_user1_status_data'];
     $doc_data['user_status_2'] = $data['letters_doc_frm_user2_status_data'];
     $doc_data['user_status_3'] = $data['letters_doc_frm_user3_status_data'];
     $doc_data['user_status_date_1'] = $data['letters_doc_frm_user1_status_date_data'];
     $doc_data['user_status_date_2'] = $data['letters_doc_frm_user2_status_date_data'];
     $doc_data['user_status_date_3'] = $data['letters_doc_frm_user3_status_date_data'];
     $doc_data['is_user_1_company'] = $data['letters_doc_frm_user_1_section'] ? 't' : 'f';
     $doc_data['is_user_2_company'] = $data['letters_doc_frm_user_2_section'] ? 't' : 'f';
     $doc_data['is_user_3_company'] = $data['letters_doc_frm_user_3_section'] ? 't' : 'f';
     $doc_data['withoutourdoc'] = $data['withoutourdoc'] ? 't' : 'f';
     if (isset($data['letters_doc_frm_comment']) && $data['letters_doc_frm_comment']) {
         $doc_data['comment'] = $data['letters_doc_frm_comment'];
     } else {
         $data['letters_doc_frm_comment'] = $doc['comment'];
     }
     if ($doc_data['user_status_1'] != $doc['user_status_1'] || $doc_data['user_status_2'] != $doc['user_status_2'] || $doc_data['user_status_3'] != $doc['user_status_3']) {
         letters::updateDateStatusChange($id);
     }
     letters::saveHistory($id, $doc_data);
     $sql = "UPDATE letters SET\n                                     date_add = " . ($data['letters_doc_frm_dateadd_eng_format'] ? "'{$data['letters_doc_frm_dateadd_eng_format']}'" : "NOW()") . ",\n                                     title = ?,\n                                     user_1 = ?,\n                                     user_2 = ?,\n                                     user_3 = ?,\n                                     group_id = ?,\n                                     parent = ?,\n                                     user_status_1 = ?, \n                                     user_status_2 = ?, \n                                     user_status_3 = ?, \n                                     user_status_date_1 = ?, \n                                     user_status_date_2 = ?, \n                                     user_status_date_3 = ?,\n                                     is_user_1_company = ?,  \n                                     is_user_2_company = ?, \n                                     is_user_3_company = ?, \n                                     withoutourdoc = ?,\n                                     comment = ?\n                WHERE id = ?i;";
     $DB->query($sql, $data['letters_doc_frm_title'], $data['letters_doc_frm_user_1_db_id'], $data['letters_doc_frm_user_2_db_id'], $data['letters_doc_frm_user_3_db_id'], $data['letters_doc_frm_group_db_id'], $data['letters_doc_frm_parent_db_id'], $data['letters_doc_frm_user1_status_data'], $data['letters_doc_frm_user2_status_data'], $data['letters_doc_frm_user3_status_data'], $data['letters_doc_frm_user1_status_date_data'], $data['letters_doc_frm_user2_status_date_data'], $data['letters_doc_frm_user3_status_date_data'], $data['letters_doc_frm_user_1_section'], $data['letters_doc_frm_user_2_section'], $data['letters_doc_frm_user_3_section'], $data['letters_doc_frm_withoutourdoc'], $data['letters_doc_frm_comment'], $id);
     $sql = "UPDATE letters SET is_out=false WHERE (user_status_1 IS DISTINCT FROM 1 AND user_status_2 IS DISTINCT FROM 1 AND user_status_3 IS DISTINCT FROM 1) AND id=?i";
     $DB->query($sql, $id);
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/attachedfiles.php";
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/CFile.php";
     $attachedfiles = new attachedfiles($data['attachedfiles_session']);
     $attachedfiles_files = $attachedfiles->getFiles();
     if ($attachedfiles_files) {
         foreach ($attachedfiles_files as $attachedfiles_file) {
             $cFile = new CFile();
             $cFile->table = 'file';
             $cFile->GetInfoById($attachedfiles_file['id']);
             if ($cFile->id != $doc['file_id']) {
                 $ext = $cFile->getext();
                 $tmp_dir = "letters/";
                 $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext);
                 $tmp_name = substr_replace($tmp_name, "", 0, strlen($tmp_dir));
                 $cFile->_remoteCopy($tmp_dir . $tmp_name, true);
                 $sql = "UPDATE letters SET file_id = ?i WHERE id = ?i";
                 $DB->query($sql, $cFile->id, intval($id));
                 $cFile->delete($doc['file_id']);
             }
         }
     }
     $attachedfiles->clear();
     return $id;
 }
Exemplo n.º 13
0
 /**
  * Связывает файлы загруженные ассинхронно с сообщением
  *
  * @param   array     $files              Список загруженных файлов
  * @param   string    $login              Логин пользователя
  * @param   integer   $msg_id             ID сообщения
  * @param   boolean   $from_draft         Файлы из черновика
  */
 function addAttachedFiles($files, $msg_id, $login, $from_draft = false)
 {
     global $DB;
     if (!$login) {
         $login = $_SESSION['login'];
     }
     $bModeration = false;
     $where = " inline != TRUE";
     $attaches = CFile::selectFilesBySrc(self::FILE_TABLE, $msg_id, NULL, $where);
     //$DB->rows($sql, $msg_id);
     $old_files = array();
     if ($attaches) {
         foreach ($attaches as $f) {
             array_push($old_files, $f['fid']);
         }
     }
     if ($from_draft) {
         $notdeleted_files = array();
         if ($files) {
             foreach ($files as $f) {
                 if ($f['status'] == 3) {
                     array_push($notdeleted_files, $f['id']);
                 }
             }
         }
         if ($attaches) {
             $cfile = new CFile();
             foreach ($attaches as $attach) {
                 if (in_array($attach['id'], $notdeleted_files)) {
                     continue;
                 }
                 $cfile->Delete(0, "users/" . substr($login, 0, 2) . "/" . $login . "/upload/", $attach['fname']);
                 //if ($attach['small'] == 't') {
                 //    $cfile->Delete(0, "users/" . substr($login, 0, 2) . "/" . $login . "/upload/", "sm_" . $attach['fname']);
                 //}
             }
         }
     }
     $max_image_size = array('width' => 470, 'height' => 1000, 'less' => 0);
     if ($files) {
         $cfile = new CFile();
         $num = 0;
         foreach ($files as $file) {
             switch ($file['status']) {
                 case 3:
                     $num++;
                     break;
                 case 4:
                     // Удаляем файл
                     $cFile = new CFile($file['id']);
                     $cFile->table = self::FILE_TABLE;
                     if ($cFile->id) {
                         $cFile->updateFileParams(array('src_id' => null), false);
                         // Удаляем связь
                         $cFile->Delete($cFile->id);
                     }
                     break;
                 case 1:
                     $num++;
                     if (in_array($file['id'], $old_files)) {
                         $need_copy = false;
                     } else {
                         $bModeration = true;
                         $need_copy = true;
                     }
                     // Добавляем файл
                     $cFile = new CFile($file['id']);
                     $cFile->proportional = 1;
                     $cFile->table = self::FILE_TABLE;
                     $ext = $cFile->getext();
                     if ($need_copy) {
                         $tmp_dir = "users/" . substr($login, 0, 2) . "/" . $login . "/upload/";
                         $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext);
                         $tmp_name = substr_replace($tmp_name, "", 0, strlen($tmp_dir));
                         $cFile->_remoteCopy($tmp_dir . $tmp_name, true);
                     }
                     if (in_array($ext, $GLOBALS['graf_array'])) {
                         $is_image = TRUE;
                     } else {
                         $is_image = FALSE;
                     }
                     if ($is_image && $ext != 'swf' && $ext != 'flv') {
                         if ($cFile->image_size['width'] > $max_image_size['width'] || $cFile->image_size['height'] > $max_image_size['height']) {
                             if ($need_copy) {
                                 if ($cFile->resizeImage($cFile->path . 'sm_' . $cFile->name, $max_image_size['width'], $cFile->image_size['height'], 'landscape')) {
                                     $cFile->small = true;
                                 }
                             } else {
                                 $cFile->small = true;
                             }
                         } else {
                             $cFile->small = false;
                         }
                     } else {
                         $cFile->small = false;
                     }
                     $cFile->updateFileParams(array('src_id' => $msg_id, 'small' => $cFile->small, 'sort' => $num), false);
                     //$sql = "INSERT INTO commune_attach(cid, fid, small, sort) VALUES(?i, ?i, ?b, ?i)";
                     //$DB->query($sql, $msg_id, $cFile->id, $cFile->small, $num);
                     break;
             }
         }
     }
     if ($bModeration && $login == $_SESSION['login'] && !hasPermissions('communes') && !is_pro()) {
         // отравляет сообщение на модерирование сразу по факту создания или редактирования
         // появились новые файлы и это правит автор - отправить на модерирование
         /*$sId = $DB->query( 'UPDATE commune_messages SET moderator_status = 0 WHERE id = ?i AND user_id = ?i  RETURNING id', $msg_id, $_SESSION['uid'] );
           
           if ( $sId ) {
               require_once( $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php' );
               $DB->insert( 'moderation', array('rec_id' => $msg_id, 'rec_type' => user_content::MODER_COMMUNITY) );
           }*/
     }
 }
Exemplo n.º 14
0
                   </table:table-cell>
                   <table:table-cell office:value-type="string">
                     <text:p>An online map</text:p>
                   </table:table-cell>
                   <table:table-cell office:value-type="string">
                     <text:p>
                       <text:a xlink:type="simple" xlink:href="http://maps.google.com/"
                         >http://maps.google.com</text:a>
                     </text:p>
                   </table:table-cell>
                 </table:table-row>
               </table:table>
';
*/
$descr_tz = '
               111
               <text:h text:outline-level="1"> A Table (Heading 1)</text:h>
               <text:p>222</text:p>
               <text:a xlink:type="simple" xlink:href="http://www.flickr.com/services/api/">http://www.flickr.com/services/api/</text:a>
';
$act_new = array('$sbr_num' => "СБР-109-Б/О-1", '$date_act' => "12.09.2012", '$date_sbr' => "12.09.2012", '$efio' => "Резидент Республики Беларусь", '$ffio' => "Александр Сергеевич Буров", '$sum_frl' => num2strEx($sum_frl, 'рублей Российской Федерации'), '$sum_emp' => num2strEx($sum_emp, 'рублей Российской Федерации'), '$tz_descr' => $descr_tz, '$work_time' => '3 дня на этап', '$work_type' => 'Промежуточной стоимости Работы', '$work_cost' => num2strEx($work_cost, 'рублей Российской Федерации'), '$is_arb_emp' => false, '$is_arb_frl' => false, '$user_arb' => 'Заказчик', '$result_arb' => 'Результат арбитража вынес потому что не работал такой то человек');
$t = new odt2pdf('arb_frl_soglashenie.odt');
$t->convert($act_new);
$content = $t->Output(NULL, 'S');
$file = new CFile();
//$file->table = 'file_sbr';
$file->path = 'uploader/';
$file->name = basename($file->secure_tmpname($file->path, '.pdf'));
$file->size = strlen($content);
$file->putContent($file->path . $file->name, $content);
//echo strlen($t->output);
Exemplo n.º 15
0
 /**
  * Связывает файлы загруженные ассинхронно с сообщением
  *
  * @param   array     $files              Список загруженных файлов
  * @param   string    $login              Логин пользователя
  * @param   integer   $msg_id             ID сообщения
  * @param   boolean   $from_draft         Файлы из черновика
  */
 function addAttachedFiles($files, $msg_id, $login = NULL, $from_draft = false)
 {
     global $DB;
     if (!$login) {
         $login = $_SESSION['login'];
     }
     $bModeration = false;
     $old_files = $this->getAttachedFiles($msg_id);
     if ($from_draft) {
         $notdeleted_files = array();
         if ($files) {
             foreach ($files as $f) {
                 if ($f['status'] == 3 || in_array($f['id'], $old_files)) {
                     array_push($notdeleted_files, $f['id']);
                 }
             }
         }
         $attaches = CFile::selectFilesBySrc(self::FILE_TABLE, $msg_id);
         if ($attaches) {
             foreach ($attaches as $attach) {
                 if (in_array($attach['id'], $notdeleted_files)) {
                     continue;
                 }
                 $cFile = new CFile($attach['id']);
                 $cFile->table = self::FILE_TABLE;
                 if ($cFile->id) {
                     $cFile->Delete($cFile->id);
                 }
             }
         }
     }
     $max_image_size = array('width' => blogs::MAX_IMAGE_WIDTH, 'height' => blogs::MAX_IMAGE_HEIGHT, 'less' => 0);
     if ($files) {
         foreach ($files as $file) {
             switch ($file['status']) {
                 case 4:
                     // Удаляем файл
                     $cFile = new CFile($file['id']);
                     $cFile->table = self::FILE_TABLE;
                     if ($cFile->id) {
                         $cFile->Delete($cFile->id);
                     }
                     break;
                 case 1:
                     if (in_array($file['id'], $old_files)) {
                         $need_copy = false;
                     } else {
                         $bModeration = true;
                         $need_copy = true;
                     }
                     // Добавляем файл
                     $cFile = new CFile($file['id']);
                     $cFile->proportional = 1;
                     $cFile->table = self::FILE_TABLE;
                     $ext = $cFile->getext();
                     if ($need_copy) {
                         $tmp_dir = "users/" . substr($login, 0, 2) . "/" . $login . "/upload/";
                         $tmp_name = $cFile->secure_tmpname($tmp_dir, '.' . $ext);
                         $tmp_name = substr_replace($tmp_name, "", 0, strlen($tmp_dir));
                         $cFile->_remoteCopy($tmp_dir . $tmp_name, true);
                     }
                     if (in_array($ext, $GLOBALS['graf_array'])) {
                         $is_image = TRUE;
                     } else {
                         $is_image = FALSE;
                     }
                     if ($is_image && $ext != 'swf' && $ext != 'flv') {
                         if ($cFile->image_size['width'] > $max_image_size['width'] || $cFile->image_size['height'] > $max_image_size['height']) {
                             if ($need_copy) {
                                 if ($cFile->resizeImage($cFile->path . 'sm_' . $cFile->name, $max_image_size['width'], $cFile->image_size['height'], 'landscape')) {
                                     $cFile->small = 2;
                                 }
                             } else {
                                 $cFile->small = 2;
                             }
                         } else {
                             $cFile->small = 1;
                         }
                     } else {
                         $cFile->small = $ext == 'flv' ? 2 : 0;
                     }
                     $cFile->updateFileParams(array('src_id' => $msg_id, 'small' => $cFile->small), false);
                     break;
             }
         }
     }
     if ($bModeration && $login == $_SESSION['login'] && !hasPermissions('blogs')) {
         // отравляем сообщение на модерирование сразу по факту создания или редактирования
         // появились новые файлы и это правит автор, и он не админ и не ПРО - отправить на модерирование
         /*require_once( $_SERVER['DOCUMENT_ROOT'] . '/classes/user_content.php' );
           $DB->query( 'UPDATE blogs_msgs SET moderator_status = 0 WHERE id = ?i', $msg_id );
           $DB->insert( 'moderation', array('rec_id' => $msg_id, 'rec_type' => user_content::MODER_BLOGS) );*/
     }
 }
 /**
  * Перенос файлов в рабочие папки сайта
  * 
  * @param array  $files   Массив файлов
  * @param string $table   Таблица для переноса
  * @param string $dir     Директория для переноса
  * @param bool = true $newName  Генерировать новое имя файла
  * @return array 
  */
 function transferFiles($files, $table, $dir, $newName = true)
 {
     foreach ($files as $key => $file) {
         $objFile = new CFile($file['id']);
         $ext = $objFile->getext();
         if (!$newName) {
             $tmp_name = $objFile->name;
         } else {
             $tmp_name = $objFile->secure_tmpname($dir, '.' . $ext);
             $tmp_name = substr_replace($tmp_name, "", 0, strlen($dir));
         }
         $objFile->table = $table;
         $copy = $objFile->_remoteCopy($dir . $tmp_name);
         $data[] = array('fname' => $objFile->name, 'id' => $objFile->id, 'orig_name' => $objFile->original_name, 'file_id' => $objFile->id);
         unset($objFile);
     }
     return $data;
 }
Exemplo n.º 17
0
 /**
  * Перемещаем файл куда надо
  * 
  * @param integer $id_file     ИД файла который нужно переместить
  * @param string  $copy_table  Таблица в которую перемещаем
  * @param string  $dir         Директория в которую копируем
  * @return \CFile
  */
 function remoteCopy($id_file, $copy_table, $dir, $new_name = true, $prefix = 'f_')
 {
     $CFile = new CFile($id_file);
     $CFile->table = $copy_table;
     if ($new_name) {
         $tmp_name = $CFile->secure_tmpname($dir, '.' . $CFile->getext(), $prefix);
         $tmp_name = substr_replace($tmp_name, "", 0, strlen($dir));
     } else {
         $tmp_name = $prefix . str_replace(array("f_", "sm_"), "", $CFile->name);
     }
     $CFile->_remoteCopy($dir . $tmp_name);
     return $CFile;
 }