public function add($fields) { $count = count($fields['answers']); $_fields['question'] = $fields['question']; $_fields2 = array(); for ($i = 0; $count > $i; $i++) { if (empty($fields['answers'][$i])) { continue; } $_fields2[] = array('answer' => $fields['answers'][$i], 'weight' => $fields['weights'][$i]); } if (count($_fields2) < 2) { $this->errors['answers'] = 'Обязательно минимум 2 заполненых варианта ответа'; return false; } if ($this->db->beginTransaction('poll_add')) { $pid = parent::add($_fields); if ($pid > 0) { $mPollA = M_PollAnswers::Instance(); foreach ($_fields2 as $_field) { $_field['pid'] = $pid; $aid = $mPollA->add($_field); if ($aid == false) { $this->errors = array_merge($this->errors, $mPollA->errors); break; } } if ($aid > 0 && $this->db->commit('poll_add')) { return $pid; } } $this->db->rollBack('poll_add'); } return false; }
public function add($fields) { // Проверка на существования родителя if (!$this->checkParent($fields)) { return false; } $fields['link_path'] = ltrim($fields['link_path'], '/'); return parent::add($fields); }
public function addmail($fields, $files) { $this->errors = array(); $mFiles = M_Files::Instance(); if (!$files['htmlfile']['name'] || M_Files::get_extention_file($files['htmlfile']['name']) != 'html') { $this->errors['htmlfile'] = 'Не выбран html файл или неверный формат'; } if (!$files['txtfile']['name'] || M_Files::get_extention_file($files['txtfile']['name']) != 'txt') { $this->errors['txtfile'] = 'Не выбран txt файл или неверный формат'; } if (!empty($this->errors)) { return false; } $mailid = parent::add($fields); if (!$mailid) { return false; } $folder = SITE_ROOT . '/' . MAILING_DIR . (int) $fields['listid'] . '/'; @mkdir($folder, 0700); $folder .= $mailid . '/'; @mkdir($folder, 0700); $html = $mFiles->upload_file($files['htmlfile'], $folder, null, array('html' => array('text/html')), 'index'); //rename($folder.$html, $folder.'index.html'); $txt = $mFiles->upload_file($files['txtfile'], $folder, null, array('txt' => array('text/plain')), 'text'); //rename($folder.$txt, $folder.'text.txt'); $image = array(); $images = array(); $i = 0; while ($files['images']['name'][$i] && $files['images']['tmp_name'][$i] != 'none') { $image['name'] = $files['images']['name'][$i]; $image['type'] = $files['images']['type'][$i]; $image['tmp_name'] = $files['images']['tmp_name'][$i]; $image['error'] = $files['images']['error'][$i]; $image['size'] = $files['images']['size'][$i]; $img_new_name = M_Files::get_name_without_ext($image['name']); $file = $mFiles->set_type('image')->upload_file($image, $folder, null, null, $img_new_name); $filename = isset($file['name']) ? $file['name'] : ''; if ($filename && ($size = getimagesize($folder . $filename))) { $images[] = array('name' => $filename, 'mime' => $size['mime']); } ++$i; } if (!empty($images)) { $this->edit($mailid, array('images' => base64_encode(serialize($images)))); } return true; }
public function add($fields) { if ($this->db->beginTransaction('menu_add')) { $menu_id = parent::add($fields); $block_id = 0; if ($menu_id > 0) { $fields2 = array(); $fields2['block_name'] = 'menu_' . $menu_id; $fields2['block_title'] = $fields['menu_title']; $fields2['block_desc'] = 'Меню'; $block_id = M_Blocks::Instance()->add($fields2); } if ($block_id > 0) { $res = $this->edit($menu_id, array('block_id' => $block_id)); } else { $res = false; } if ($res === true && $this->db->commit('menu_add')) { return $menu_id; } $this->db->rollBack('menu_add'); } return false; }
public function add($fields) { $fields['post_date_create'] = date('Y-m-d H:i:s'); $fields2 = array(); $errors = false; $errorsMLink = array(); if ($this->db->beginTransaction('posts_add')) { // Вставляем "запись" if (!($post_id = parent::add($fields))) { $errors = true; } // Добавляем пункт, если указан if ($errors === false && isset($fields['parent']) && substr_count($fields['parent'], ':') == 1) { $parent = explode(':', $fields['parent']); $menu_id = (int) $parent[0]; $plid = (int) $parent[1]; $fields_menu = array(); $fields_menu['link_title'] = $fields['link_title']; $fields_menu['menu_id'] = $menu_id; $fields_menu['plid'] = $plid; $fields_menu['link_description'] = $fields['link_description']; $link = M_Link::ToPage('post', $post_id); $fields_menu['link_path'] = strpos($link, BASE_URL) === 0 ? mb_substr($link, iconv_strlen(BASE_URL)) : $link; $mMenuLink = M_MenuLink::Instance(); if (!($mlid = $mMenuLink->add($fields_menu))) { $errors = true; $errorsMLink = $mMenuLink->errors(); } else { $fields2['mlid'] = $mlid; } } // Если включена сортировка картинок по папкам if ($errors === false && $this->ck_sort_img_folder === true) { $search = 'post_0_' . $this->ck_temp_prefix; $replace = "post_{$post_id}"; $src_images = array(); // Заменяем пути картинок в поле $fields2['post_content'] = $this->replace_img_in_src($search, $replace, $fields['post_content'], $src_images); // Создаем папку для картинок поста $folder_post = $this->ckupload_dir . $replace . '/'; if (!is_dir($folder_post)) { mkdir($folder_post); } // Перемешаем картинки из временной папки foreach ($src_images as $link) { $this->move_file($link['last'], $link['new']); } } if ($errors === false && !empty($fields2)) { // Обновляем запись в базе данных if (!parent::edit($post_id, $fields2)) { $errors = true; } } if ($errors === false && $this->db->commit('posts_add')) { return $post_id; } $this->db->rollBack('posts_add'); } $this->errors = array_merge($this->errors, $errorsMLink); return false; }
public function addFile($files, $type, $fields = array()) { $path = ""; switch ($type) { case 'audio': $path = $this->audioDir; break; case 'video': $path = $this->videoDir; break; } if (empty($path)) { return false; } $folder = SITE_ROOT . '/' . $path; $mFiles = M_Files::Instance()->set_type($type); $_file = $mFiles->upload_file($files, $folder); if (!$_file) { $this->errors['file_error'] = $mFiles->error(); return false; } $file['name'] = $_file['name']; $file['type'] = $type; //$title = mb_substr($files['name'], 0, (int)mb_strrpos($files['name'], '.')); $title = M_Files::get_name_without_ext($files['name']); $file['title'] = isset($field['title']) ? $field['title'] : $title; return parent::add($file); }