Beispiel #1
0
 public function saveDesign()
 {
     $results = array();
     // check user login
     $user = $this->session->userdata('user');
     if (empty($user['id'])) {
         $results['error'] = 1;
         $results['login'] = 1;
         $results['msg'] = lang('design_msg_save_login');
         echo json_encode($results);
         exit;
     }
     $data = json_decode(file_get_contents('php://input'), true);
     $this->load->helper('file');
     $path = ROOTPATH . DS . 'media' . DS . 'assets' . DS . 'system';
     $temp = explode(';base64,', $data['image']);
     $buffer = base64_decode($temp[1]);
     $design = array();
     $design['user_id'] = $user['id'];
     $design['vectors'] = $data['vectors'];
     $design['teams'] = $data['teams'];
     $design['fonts'] = $data['fonts'];
     $designer_id = $data['designer_id'];
     // check design and author
     if ($data['design_file'] != '' && $designer_id == $design['user_id']) {
         // override file and update
         $file = $data['design_file'];
         $path_file = ROOTPATH . DS . str_replace('/', DS, $file);
         $id = $data['design_id'];
         $key = $data['design_key'];
     } else {
         // save new file
         $this->load->library('file');
         $file = new file();
         // create path file
         $date = new DateTime();
         $year = $date->format('Y');
         $file->create($path . DS . $year, 0755);
         $month = $date->format('m');
         $file->create($path . DS . $year . DS . $month, 0755);
         $key = strtotime("now") . rand();
         $file = $key . '.png';
         $path_file = $path . DS . $year . DS . $month . DS . $file;
         $file = 'media/assets/system/' . $year . '/' . $month . '/' . $file;
         $id = null;
         $design['design_id'] = $key;
     }
     if (!write_file($path_file, $buffer)) {
         $results['error'] = 1;
         $results['msg'] = lang('design_msg_save');
     } else {
         $design['image'] = $file;
         $design['product_id'] = $data['product_id'];
         $design['product_options'] = $data['product_color'];
         $design['title'] = '';
         $design['description'] = '';
         $design['system_id'] = '';
         $this->load->model('design_m');
         $id = $this->design_m->save($design, $id);
         if ($id > 0) {
             $results['error'] = 0;
             $content = array('design_id' => $id, 'design_key' => $key, 'designer_id' => $user['id'], 'design_file' => $file);
             $results['content'] = $content;
             // send email savedesign.
             //params shortcode email.
             $params = array('username' => $user['username'], 'url_design' => site_url('design/index/' . $data['product_id'] . '/' . $data['product_color'] . '/' . $key));
             //config email.
             $config = array('mailtype' => 'html');
             $subject = configEmail('sub_save_design', $params);
             $message = configEmail('save_design', $params);
             $this->load->library('email', $config);
             $this->email->from(getEmail(config_item('admin_email')), getSiteName(config_item('site_name')));
             $this->email->to($user['email']);
             $this->email->subject($subject);
             $this->email->message($message);
             $this->email->send();
         } else {
             $results['error'] = 1;
             $results['msg'] = lang('design_msg_save');
         }
     }
     echo json_encode($results);
 }
Beispiel #2
0
function createFile($data, $prefix = '', $filename = '', $file_url = '')
{
    $path = ROOTPATH . DS . 'media' . DS . 'assets' . DS . 'system';
    $CI = get_instance();
    if ($file_url == '') {
        $CI->load->library('file');
        $file = new file();
        $date = new DateTime();
        $year = $date->format('Y');
        $file->create($path . DS . $year, 0755);
        $month = $date->format('m');
        $file->create($path . DS . $year . DS . $month, 0755);
        if ($filename == '') {
            $file = $prefix . '_' . strtotime("now") . '.png';
        } else {
            $file = $prefix . '_' . $filename . '.png';
        }
        $path_file = $path . DS . $year . DS . $month . DS . $file;
        $file = 'media/assets/system/' . $year . '/' . $month . '/' . $file;
    } else {
        $path_file = $path . DS . str_replace('/', DS, $file_url);
    }
    $temp = explode(';base64,', $data);
    $buffer = base64_decode($temp[1]);
    $CI->load->helper('file');
    if (!write_file($path_file, $buffer)) {
        return '';
    } else {
        return $file;
    }
}
Beispiel #3
0
 function add()
 {
     $path = $this->input->post('path');
     $folder = $this->input->post('folder');
     $this->load->library('file');
     $file = new file();
     $path = $this->root . DS . $path . DS . $folder;
     $check = $file->create($path, 0755);
     if ($check == false) {
         echo lang('media_exists');
     } else {
         echo 1;
     }
     exit;
 }