Пример #1
0
 public static function edit_store($id, $user, $post)
 {
     global $db, $LANG;
     $post = array_map('trim', $post);
     if (!\query\main::have_store($id, $user)) {
         throw new \Exception($LANG['msg_error']);
         // this error can appear only when user try to modify post data
     } else {
         if (!isset($post['name']) || trim($post['name']) == '') {
             throw new \Exception($LANG['edit_store_writename']);
         } else {
             if (!isset($post['url']) || !preg_match('/(^http(s)?:\\/\\/)([a-zA-Z0-9-]{3,100}).([a-zA-Z]{2,12})/', $post['url'])) {
                 throw new \Exception($LANG['edit_store_wrongweb']);
             } else {
                 if (!isset($post['description']) || strlen($post['description']) < 10) {
                     throw new \Exception($LANG['edit_store_writedesc']);
                 } else {
                     $store = \query\main::store_infos($id);
                     $logo = \site\images::upload($_FILES['edit_store_form_logo'], 'logo_', array('path' => '', 'max_size' => 400, 'max_width' => 600, 'max_height' => 400, 'current' => $store->image));
                     $stmt = $db->stmt_init();
                     $stmt->prepare("UPDATE " . DB_TABLE_PREFIX . "stores SET category = ?, name = ?, link = ?, description = ?, tags = ?, image = ?, lastupdate_by = ?, lastupdate = NOW() WHERE id = ?");
                     $tags = isset($post['tags']) ? $post['tags'] : '';
                     $stmt->bind_param("isssssii", $post['category'], $post['name'], $post['url'], $post['description'], $tags, $logo, $user, $id);
                     $execute = $stmt->execute();
                     $stmt->close();
                     if ($execute) {
                         return (object) array('image' => $logo);
                     } else {
                         throw new \Exception($LANG['msg_error']);
                     }
                 }
             }
         }
     }
 }