Beispiel #1
0
 private function saveProduct($is_new = true)
 {
     if ($is_new == true && $this->req['product']['name'] == "" || $this->req['product']['id'] == "" && $is_new == false) {
         return false;
     }
     $valid = true;
     // add checks here
     if ($valid == true) {
         $file = new FileTransfer();
         $json_template = json_decode($this->req['product']['templatefile'], true);
         $images = "";
         if (isset($json_template['objects'][0])) {
             foreach ($json_template['objects'] as $k => $v) {
                 if ($v['type'] == "image" && strpos($v['src'], "/temp/") != false) {
                     $new_url = $file->move($v['src']);
                     if ($new_url != "") {
                         $this->req['product']['templatefile'] = str_replace($v['src'], $new_url, $this->req['product']['templatefile']);
                     }
                 }
                 if ($v['type'] == "image") {
                     $images = $images . "##" . $v['src'];
                 }
             }
         }
         if ($json_template['overlayImage']['type'] == "image") {
             $new_url = $file->move($json_template['overlayImage']['src']);
             if ($new_url != "") {
                 $this->req['product']['templatefile'] = str_replace($json_template['overlayImage']['src'], $new_url, $this->req['product']['templatefile']);
             }
         }
         if ($is_new == true) {
             $this->productModel = new ProductModel();
         } else {
             $temp = $this->productModel->fetchProductById($this->req['product']['id']);
             $this->productModel = $temp[0];
             $str_old_template = $this->productModel->getTemplateFile();
             $json_old_template = json_decode($str_old_template, true);
             if (isset($json_old_template['objects'][0])) {
                 foreach ($json_old_template['objects'] as $k => $v) {
                     if ($v['type'] == "image" && strpos($images, $v['src']) == false) {
                         $file->delete($v['src']);
                     }
                 }
             }
             $this->productModel->setProductId($this->req['product']['id']);
         }
         $this->productModel->setTitle($this->req['product']['name']);
         $this->productModel->setSku($this->req['product']['sku']);
         $this->productModel->setModel($this->req['product']['model']);
         $this->productModel->setDescription($this->req['product']['description']);
         $this->productModel->setInStock($this->req['product']['instock']);
         $this->productModel->setInsertTime(date('Y-m-d H:i:s'));
         $this->productModel->setIsActive($this->req['product']['status']);
         $this->productModel->setMetaDescription($this->req['product']['meta_description']);
         $this->productModel->setMetaKeywords($this->req['product']['meta_keywords']);
         $this->productModel->setPrice($this->req['product']['price']);
         $this->productModel->setQty($this->req['product']['qty']);
         $this->productModel->setSummary($this->req['product']['summary']);
         if (strlen($this->req['product']['templatefile']) < 40) {
             $this->req['product']['templatefile'] = "";
         }
         $this->productModel->setTemplateFile($this->req['product']['templatefile']);
         $this->productModel->setUpdateTime(date('Y-m-d H:i:s'));
         $this->productModel->setCategories("," . implode(",", $this->req['product']['categories']) . ",");
         $this->productModel->setSalePrice($this->req['product']['sprice']);
         $this->productModel->setSoldQty($this->req['product']['sold_qty']);
         $this->productModel->setPreference($this->req['product']['pref']);
         $fileurl = $file->upload('fileupload1');
         $fileurl = $file->move($fileurl);
         if ($is_new == true) {
             $this->productModel->setImageFile($fileurl);
             $this->productModel->insert();
         } else {
             if ($fileurl != "") {
                 $file->delete($this->productModel->getImageFile());
                 $this->productModel->setImageFile($fileurl);
             }
             $this->productModel->update();
         }
         if (is_array($this->req['product']['atr']) && count($this->req['product']['atr']) > 0) {
             $ahc = new AttributeHelper();
             $ahc->saveProductAttributesValue($this->req['product']['atr'], $this->productModel->getProductId());
         }
         if ($this->productModel->isSuccess() == 1) {
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function getSettingsForm()
 {
     $form = parent::getSettingsForm();
     $form['advanced']['port']['#default_value'] = 21;
     return $form;
 }
Beispiel #3
0
 public function downloadzip($orderid)
 {
     if ($this->isAdmin == true) {
         if ($orderid != "") {
             $data = $this->getOrderDetails($orderid);
             $filetrans = new FileTransfer();
             if ($data != null) {
                 foreach ($data['orderdetail'] as $od) {
                     if ($od['t'] != null) {
                         $file64 = $od['t']->getTemplateimage();
                         $filesUrls[] = $filetrans->base64ToImage($file64, $od['p']->getProductid() . "_" . @str_replace(" ", "-", $od['p']->getModel()) . "_" . $od['t']->getTemplateid());
                         $json_template = json_decode($od['t']->getTemplate(), true);
                         if (isset($json_template['objects'][0])) {
                             foreach ($json_template['objects'] as $k => $v) {
                                 if ($v['type'] == "image") {
                                     $filesUrls[] = $v['src'];
                                 }
                             }
                         }
                     } else {
                         $filesUrls[] = $od['p']->getImageFile();
                     }
                     $name .= $od['p']->getModel() . "_";
                 }
                 $return = $filetrans->generateZip($orderid . "_" . $name . rand(0, 1000), $filesUrls);
                 if ($data['order']->getStatus() == "pending") {
                     $data['order']->setStatus("printing");
                     $data['order']->update();
                 }
             }
         }
     }
     if ($return == "") {
         echo "failed";
     } else {
         echo $return;
     }
 }
Beispiel #4
0
 private function moveTemplate($tid)
 {
     // converts file urls from temp dir to final destination dir and update user templates database records
     $file = new FileTransfer();
     $templateModel = new UsertemplateModel();
     $templates = $templateModel->fetchTemplatesfromIds($tid);
     $template = $templates[0];
     if ($template) {
         $json_template_str = $template->getTemplate();
         $json_template = json_decode($json_template_str, true);
         $images = "";
         if (isset($json_template['objects'][0])) {
             foreach ($json_template['objects'] as $k => $v) {
                 if ($v['type'] == "image" && strpos($v['src'], "/temp/") != false) {
                     $new_url = $file->move($v['src']);
                     if ($new_url != "") {
                         $json_template_str = str_replace($v['src'], $new_url, $json_template_str);
                     }
                 }
                 if ($v['type'] == "image") {
                     $images = $images . "##" . $v['src'];
                 }
             }
         }
         if ($json_template['overlayImage']['type'] == "image") {
             $new_url = $file->move($json_template['overlayImage']['src']);
             if ($new_url != "") {
                 $json_template_str = str_replace($json_template['overlayImage']['src'], $new_url, $json_template_str);
             }
         }
         $template->setTemplate($json_template_str);
         $template->update();
     }
 }
function downloadaFile()
{
    $ft = new FileTransfer($_SESSION['sHost'], $_SESSION['sApp'], $_SESSION['sUserAgent']);
    $var0 = trim($_POST['token'], " ");
    $ft->setAuthToken($var0);
    $var1 = trim($_POST['durl'], " ");
    $ft->setAuthToken($var0);
    if (isset($_POST['psw'])) {
        $var2 = trim($_POST['psw'], " ");
        $response = $ft->downloadaFileWS($var1, $var2);
    } else {
        $response = $ft->downloadaFileWS($var1);
    }
    if ($response !== 'fail') {
        header("Location: {$response}");
    } else {
        header("Location: ./dwn.php?err=3");
    }
}
Beispiel #6
0
 public function index()
 {
     $ft = new FileTransfer();
     echo $ft->upload("fileupload");
 }
     $config[$update_id] = new stdClass();
     $config[$update_id]->sitename = '';
     // 新規の場合はパスワード必須
     $config[$update_id]->password = required_param("password{$update_id}");
 } else {
     // 更新の場合はパスワードがフォームに自動入力されないので
     // 入力値が空でなければ更新
     if ($new_password = optional_param("password{$update_id}")) {
         $config[$update_id]->password = $new_password;
     }
 }
 if (!empty($url)) {
     // リポジトリサイト名をHTTP通信で取得
     require_once './lib/FileTransfer.php';
     $tmp_file = tempnam(make_upload_directory('temp/download', FALSE), 'title');
     $response = FileTransfer::downloadFile($tmp_file, "{$url}/course/format/repository/title.php", array('instance' => $instance, 'username' => $config[$update_id]->username, 'password' => $config[$update_id]->password, 'usersite' => $CFG->wwwroot, 'sitename' => $SITE->fullname));
     if (preg_match('@^HTTP/1.. (\\d+) @', $response, $m)) {
         // HTTPステータスコード
         $status_code = intval($m[1]);
         switch ($status_code) {
             case 200:
                 // OK
                 $sitename = file_get_contents($tmp_file);
                 if (strspn($sitename, "\r\n")) {
                     // 改行文字が含まれていたらRepository側で
                     // PHPエラーが発生したと判断
                 } else {
                     $config[$update_id]->sitename = $sitename;
                     SharingCart_Repository::setConfig($USER, $config);
                     $succeeded = TRUE;
                 }
Beispiel #8
0
 public function downloada_file($download_url = null)
 {
     $ft = new \FileTransfer(\Session::get('ysi.sHost'), \Session::get('ysi.sApp'), \Session::get('ysi.sUserAgent'));
     $ft->setAuthToken(\Session::get('ysi.sToken'));
     $response = $ft->downloadaFileWS(trim($download_url));
     if ($response !== 'fail') {
         header("Location: {$response}");
     } else {
         echo '<h3>There was an error while downloading file.</h3>';
     }
     exit;
 }
 foreach ($materials as $id => $fields) {
     // フィールドを分解
     // @see /course/format/repository/RepositoryMaterial.php # download()
     list($sha1, $type, $icon, $text) = explode('|', $fields, 4);
     // ダウンロードボタンがクリックされたら、教材ファイルをHTTP通信により取得
     if (!empty($downloads[$id])) {
         $user_dir = make_user_directory($USER->id);
         $temp_dir = make_upload_directory('temp/download', false);
         $zip_name = SharingCart_Repository::getDownloadName($id);
         if (!is_dir($user_dir) || !is_dir($temp_dir)) {
             throw new SharingCart_RepositoryException('Directory creation failure');
         }
         if (is_file($user_dir . '/' . $zip_name)) {
             throw new SharingCart_RepositoryException('File already exists');
         }
         $response_header = FileTransfer::downloadFile($temp_dir . '/' . $zip_name, $repository_wwwroot . '/course/format/repository/material.php', array('mode' => 'transfer', 'material' => $id, 'sessionkey' => $sessionkey));
         // ダウンロードしたファイルのハッシュを比較してダウンロード成功かチェック
         if (sha1_file($temp_dir . '/' . $zip_name) == $sha1) {
             if (!rename($temp_dir . '/' . $zip_name, $user_dir . '/' . $zip_name)) {
                 throw new SharingCart_RepositoryException('File rename failure');
             }
             $sharing_cart = new stdClass();
             $sharing_cart->user = $USER->id;
             $sharing_cart->name = $type;
             $sharing_cart->icon = $icon;
             $sharing_cart->text = $text;
             $sharing_cart->time = time();
             $sharing_cart->file = $zip_name;
             sharing_cart_table::insert_record($sharing_cart);
             $completes[$id] = TRUE;
         }