示例#1
0
 public function edit_contact()
 {
     if (isset($_POST['edit_contact_btn'])) {
         $data_post = $this->input->post();
         $this->load->helper('HTMLPurifier');
         $config = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($config);
         $data_update['content'] = $purifier->purify($data_post['content_contact']);
         if ($this->Contact->update($data_update)) {
             $content = 'Cập nhật thông tin liên lạc thành công.';
             set_notice('status', SUCCESS_STATUS, $content);
             header('location:' . base_url() . 'index.php/_admin/manage_site/contact/show_contact');
         } else {
             $content = 'Cập nhật thông tin liên lạc thất bại.';
             set_notice('status', FAILED_STATUS, $content);
             header('location:' . base_url() . 'index.php/_admin/manage_site/contact/show_contact');
         }
     } else {
         $data['contact'] = $this->Contact->get_contact();
         $data['subView'] = '/manage_site/contact/edit_contact_layout';
         $data['title'] = "Cập nhật thông tin liên hệ";
         $data['subData'] = $data;
         $this->load->view('/main/main_layout', $data);
     }
 }
示例#2
0
 public function do_order()
 {
     date_default_timezone_set("Asia/Ho_Chi_Minh");
     $this->load->model('Order_model', 'Order');
     if (isset($_POST['phone'])) {
         $this->load->helper('validation');
         $customer_name = trim_input($_POST['customer_name']);
         $phone = trim_input($_POST['phone']);
         $arr_product_id = (array) $_POST['product_id'];
         $arr_order_qty = (array) $_POST['order_qty'];
         $error = array();
         //====================== VALIDATION: START ====================
         if ($customer_name == '') {
             $error[] = 'Tên khách hàng không được để trống.';
         }
         $regex = "/^[0-9]{9,11}\$/";
         if ($phone == '') {
             $error[] = "Số điện thoại không được rỗng.";
         } elseif (!preg_match($regex, $phone, $maches)) {
             $error[] = "Số điện thoại không đúng.";
         }
         if (empty($arr_product_id)) {
             $error[] = "Không có có sản phẩm nào trong đơn hàng.";
         } else {
             foreach ($arr_product_id as $key => $value) {
                 if (!$this->Product->check_product_exist($value)) {
                     $error[] = 'Sản phẩm có mã <span style="color:red;">' . $value . '</span> không có trong hệ thống.';
                 } else {
                     if ($arr_order_qty[$key] <= 0) {
                         $product_name = $this->Product->get_product_name_by_id($arr_product_id[$key]);
                         $error[] = 'Số lượng sản phẩm <span style="color:red;">' . $product_name . '</span> không thể bằng ' . '<span style="color:red;">' . $arr_order_qty[$key] . '</span>';
                     }
                 }
             }
         }
         //====================== VALIDATION: END ======================
         if (count($error) > 0) {
             set_notice('order', FAILED_STATUS, $error);
             header("location:" . base_url() . "index.php/site/cart/view_order");
         } else {
             $now = new DateTime(date('Y-m-d H:i:s'));
             $data_insert['order_datetime'] = $now->format('Y-m-d H:i:s');
             $data_insert['product_id_and_qty'] = '';
             for ($i = 0; $i < count($arr_product_id); $i++) {
                 $data_insert['product_id_and_qty'] .= $arr_product_id[$i] . '-' . $arr_order_qty[$i] . '|';
             }
             $data_insert['product_id_and_qty'] = trim($data_insert['product_id_and_qty'], '|');
             $data_insert['customer_name'] = $customer_name;
             $data_insert['phone'] = $phone;
             if ($this->Order->insert($data_insert)) {
                 $this->cart->destroy();
                 //================ SEND MAIL TO ADMIN: START ================
                 $this->load->model('Account_model', 'Account');
                 $this->load->helper('mymail');
                 $arr_to_mail = $this->Account->get_list_email_admin();
                 if (!empty($arr_to_mail)) {
                     $date_time_order = date('d/m/Y') . ' - ' . date("h:i:sa");
                     $subject = 'ĐƠN ĐẶT HÀNG MỚI (' . $date_time_order . ')';
                     $message = 'Có đơn đặt hàng mới từ:' . '<br>Khách hàng: ' . $customer_name . '<br>Số điện thoại: ' . $phone . '<br><br>';
                     $message .= '<html><body>';
                     $message .= '<table rules="all" style="min-width:300px; border-color: #666;" cellpadding="10">';
                     $message .= "<tr style='background: #eee;'><td><strong>Tên sản phẩm:</strong> </td><td>Số lượng</td></tr>";
                     foreach ($arr_product_id as $key => $value) {
                         $message .= "<tr><td><strong>" . $this->Product->get_product_name_by_id($arr_product_id[$key]) . "</strong> </td><td>" . $arr_order_qty[$key] . "</td></tr>";
                     }
                     $message .= "</table>";
                     $message .= "</body></html>";
                     send_mail($arr_to_mail, $subject, $message);
                 }
                 //================ SEND MAIL TO ADMIN: START ================
                 $content = '<div style="color: rgb(129, 127, 123); font-size: 16px;">' . 'Khách hàng: <span style="color:rgb(0, 165, 255);">' . $customer_name . '</span>' . '<br> Số điện thoại: <span style="color:rgb(0, 165, 255);">' . $phone . '</span>' . '<br><span style="color:rgb(129, 127, 123);"> Chúng tôi sẽ liên lạc lại cho quý khách trong thời gian sớm nhất!</span>' . '</div>';
                 set_notice('order', SUCCESS_STATUS, $content);
                 header("location:" . base_url());
             } else {
                 header("location:" . base_url() . "index.php/site/cart/view_order");
                 $content = 'Có lỗi trong quá trình đặt hàng. <br> Vui lòng làm lại thực hiện lại!';
                 set_notice('order', FAILED_STATUS, $content);
             }
         }
     } else {
         header("location:" . base_url());
     }
 }
示例#3
0
 function _check()
 {
     $prob = FALSE;
     if (version_compare(phpversion(), '5.2.0') < 0) {
         set_notice('error', _('You need at least PHP version 5.2.0 to run FoOlSlide. This means you have a many years old version. It is suggested to upgrade to a more recent version of PHP to avoid security issues with your server in general.'));
         $prob = TRUE;
         return FALSE;
     }
     if (!file_exists('assets/config.sample.php')) {
         set_notice('error', sprintf(_('The file %s was removed. The installation can\'t continue without that file. You can find it in the FoOlSlide download.'), FCPATH . 'config.sample.php'));
         $prob = TRUE;
         return FALSE;
     }
     if (!is_writable('content')) {
         set_notice('error', sprintf(_('The %s directory needs to be writable. Use this command in your shell if possible: %s or change its permissions recursively to 777 with your own FTP software. You won\'t be able to install or run FoOlSlide without this.'), FCPATH . 'content/', '<br/><b><code>chmod -R 777 ' . FCPATH . 'content/</code></b><br/>'));
         $prob = TRUE;
         return FALSE;
     }
     if (!is_writable('content/themes')) {
         set_notice('error', sprintf(_('The %s directory needs to be writable as well. Use this command in your shell if possible: %s or change its permissions recursively to 777 with your own FTP software. You won\'t be able to install or run FoOlSlide without this.'), FCPATH . 'content/themes', '<br/><b><code>chmod -R 777 ' . FCPATH . 'content/</code></b><br/>'));
         $prob = TRUE;
         return FALSE;
     }
     // check if base folder is writable
     if (!is_writable('.')) {
         $whoami = FALSE;
         // if exec is enable, just check with whoami function who's running php
         if ($this->_exec_enabled()) {
             $whoami = exec('whoami');
         }
         // if exec is not enabled, write a file and check who has the permissions on it
         if (!$whoami && is_writable('content') && function_exists('posix_getpwid')) {
             write_file('content/testing_123.txt', 'testing_123');
             $whoami = posix_getpwuid(fileowner('content/testing_123.txt'));
             $whoami = $whoami['name'];
             unlink('content/testing_123.txt');
         }
         // if absolutely unable to tell who's the php user, just apologize
         // else, give a precise command for shell to enter
         if ($whoami != "") {
             set_notice('warn', sprintf(_('The %s directory would be better if writable, in order to deliver automatic updates. Use this command in your shell if possible: %s'), FCPATH, '<br/><b><code>chown -R ' . $whoami . ' ' . FCPATH . '</code></b>'));
         } else {
             set_notice('warn', sprintf(_('The %s directory would be better if writable, in order to deliver automatic updates.<br/>It was impossible to determine the user running PHP. Use this command in your shell if possible: %s where www-data is an example (usually it\'s www-data or Apache)'), FCPATH, '<br/><b><code>chown -R www-data ' . FCPATH . '</code></b><br/>'));
         }
         set_notice('warn', sprintf(_('If you can\'t do the above, after the installation you will be given a textfile to paste in config.php. More info after submitting.')));
         $prob = TRUE;
     }
     // there was an issue? suggest to refresh the page to check again
     if ($prob) {
         set_notice('notice', _('If you made any changes, just refresh this page to recheck the directory permissions.'));
     }
     // all good
     return TRUE;
 }
示例#4
0
文件: comic.php 项目: Nakei/FoOlSlide
	/**
	 * Removes the thumbnail and its original image both from database and directory.
	 *
	 * @author	Woxxy
	 * @return	string true on success, false on failure.
	 */
	public function remove_comic_thumb() {

		// Get directory
		$dir = "content/comics/" . $this->directory() . "/";

		// Remove the full image
		if (!unlink($dir . $this->thumbnail)) {
			set_notice('error', _('Failed to remove the thumbnail\'s original image. Please, check file permissions.'));
			log_message('error', 'Model: comic_model.php/remove_comic_thumb: failed to delete image');
			return false;
		}

		// Remove the thumbnail
		if (!unlink($dir . "thumb_" . $this->thumbnail)) {
			set_notice('error', _('Failed to remove the thumbnail image. Please, check file permissions.'));
			log_message('error', 'Model: comic_model.php/remove_comic_thumb: failed to delete thumbnail');
			return false;
		}

		// Set the thumbnail variable to empty and save to database
		$this->thumbnail = "";
		if (!$this->save()) {
			set_notice('error', _('Failed to remove the thumbnail image from the database.'));
			log_message('error', 'Model: comic_model.php/remove_comic_thumb: failed to remove from database');
			return false;
		}

		// All's good.
		return true;
	}
示例#5
0
 /**
  * Checks if the database entry reflects the files for the page
  *
  * @author Woxxy
  * @return array with error codes (missing_page, missing_thumbnail)
  */
 public function check($repair = FALSE)
 {
     // Let's make sure the chapter and comic is set
     if ($this->get_chapter() === FALSE) {
         $errors[] = 'page_chapter_entry_not_found';
         set_notice('warning', _('Found a page entry without a chapter entry, ID: ' . $this->id));
         log_message('debug', 'check: page entry without chapter entry');
         if ($repair) {
             $this->remove_page_db();
         }
         return FALSE;
     }
     $errors = array();
     // check the files
     $path = "content/comics/" . $this->chapter->comic->directory() . "/" . $this->chapter->directory() . "/" . $this->filename;
     // get paths and remove the thumb
     if (!file_exists($path)) {
         $errors[] = 'missing_page';
         set_notice('warning', _('Page file not found in:') . ' ' . $this->chapter->comic->name . ' > ' . $this->chapter->title());
         log_message('debug', 'check_page: page not found in ' . $path);
     }
     if ($repair) {
         if (in_array('missing_page', $errors)) {
             // no better suggestion than removing
             $this->remove_page_db();
             return TRUE;
         }
     }
     return $errors;
 }
示例#6
0
 public function get_teams_id($array, $create_joint = FALSE)
 {
     if (count($array) < 1) {
         set_notice('error', _('There were no groups selected.'));
         log_message('error', 'get_groups: input array empty');
         return false;
     }
     if (count($array) == 1) {
         $team = new Team();
         $team->where("name", $array[0])->get();
         if ($team->result_count() < 1) {
             set_notice('error', _('There\'s no team under this ID.'));
             log_message('error', 'get_groups: team not found');
             return false;
         }
         $result = array("team_id" => $team->id, "joint_id" => 0);
         return $result;
     }
     if (count($array) > 1) {
         $id_array = array();
         foreach ($array as $key => $arra) {
             $team = new Team();
             $team->where('name', $arra[$key])->get();
             if ($team->result_count() < 1) {
                 set_notice('error', _('There\'s no teams under this ID.'));
                 log_message('error', 'get_groups: team not found');
                 return false;
             }
             $id_array[$key] = $team->id;
         }
         $joint = new Joint();
         if (!$joint->check_joint($id_array) && $create_joint) {
             if (!$joint->add_joint($id_array)) {
                 log_message('error', 'get_groups: could not create new joint');
                 return false;
             }
         }
         return array("team_id" => 0, "joint_id" => $joint->joint_id);
     }
     set_notice('error', _('There\'s no group found with this ID.'));
     log_message('error', 'get_groups: no case matched');
     return false;
 }
示例#7
0
 public function edit_super_category()
 {
     if (null != $this->input->post('edit_super_category_btn')) {
         $data_post = $this->input->post();
         $this->load->helper('Validation');
         $this->load->helper('HTMLPurifier');
         $config = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($config);
         $id = $data_post['super_category_id'];
         $data_update['super_categoryName'] = $purifier->purify($data_post['super_categoryName']);
         //========================= VALIDATION: START =======================
         $error = array();
         if (trim_input($data_update['super_categoryName']) == '') {
             $error = 'Tên loại danh mục không thể rỗng.';
         }
         if ($this->Category->has_duplicate_super_category_name($data_update['super_categoryName'], $id)) {
             $error = 'Loại danh mục này đã tồn tại.';
         }
         //========================= VALIDATION: END =========================
         if (count($error) > 0) {
             // has error validate
             set_notice('status', FAILED_STATUS, $error);
             $data['re_super_category_name'] = $data_post['super_categoryName'];
             $data['re_super_category_id'] = $data_post['super_category_id'];
             $data['subView'] = '/category/edit_super_category_layout';
             $data['title'] = "Cập nhật loại danh mục";
             $data['subData'] = $data;
             $this->load->view('/main/main_layout', $data);
         } else {
             // not error validate
             $old_super_category_name = $this->Category->get_super_category_name_by_id($id);
             $new_super_category_name = $data_post['super_categoryName'];
             if ($this->Category->update_super_category($id, $data_update)) {
                 if ($old_super_category_name != $new_super_category_name) {
                     $content = 'Cập nhật loại danh mục <span style="color:blue;">' . $old_super_category_name . '</span> thành <span style="color:blue;">' . $new_super_category_name . '</span>';
                 } else {
                     $content = 'Cập nhật loại danh mục <span style="color:blue;">' . $old_super_category_name . '</span> thành công.';
                 }
                 set_notice('status', SUCCESS_STATUS, $content);
                 header('location:' . base_url() . 'index.php/_admin/category/show_super_category');
             } else {
                 $content = 'Cập nhật loại danh mục <span style="color:blue;">' . $old_super_category_name . '</span> thất bại.';
                 set_notice('status', FAILED_STATUS, $content);
                 header('location:' . base_url() . 'index.php/_admin/category/show_super_category');
             }
         }
     } else {
         if (null !== $this->uri->segment(4) && is_numeric($this->uri->segment(4)) && $this->Category->has_super_category_exist_by_id($this->uri->segment(4))) {
             $super_category_id = $this->uri->segment(4);
             $data['super_category_info'] = $this->Category->get_super_category_info($super_category_id);
             $data['subView'] = '/category/edit_super_category_layout';
             $data['title'] = "Cập nhật loại danh mục";
             $data['subData'] = $data;
             $this->load->view('/main/main_layout', $data);
         } else {
             $data['pre_page'] = base_url() . 'index.php/_admin/category/show_super_category';
             $this->load->view('/error/404_layout', $data);
         }
     }
 }
示例#8
0
 function balancers()
 {
     if ($this->input->post()) {
         $result = array();
         if ($urls = $this->input->post('url')) {
             $priorities = $this->input->post('priority');
             if (is_array($urls)) {
                 foreach ($urls as $key => $item) {
                     if (!$item) {
                         unset($urls[$key]);
                         break;
                     }
                     if ($priorities[$key] >= 0 && $priorities[$key] <= 100) {
                         $result[] = array('url' => $item, 'priority' => $priorities[$key]);
                     }
                 }
             }
             $result = serialize($result);
             $this->db->from('preferences');
             $this->db->where(array('name' => 'fs_balancer_clients'));
             if ($this->db->count_all_results() == 1) {
                 $this->db->update('preferences', array('value' => $result), array('name' => 'fs_balancer_clients'));
             } else {
                 $this->db->insert('preferences', array('name' => 'fs_balancer_clients', 'value' => $result));
             }
         }
         if ($value = $this->input->post('fs_balancer_ips')) {
             if (is_array($value)) {
                 foreach ($value as $key => $val) {
                     if ($value[$key] == "") {
                         unset($value[$key]);
                     }
                 }
                 $value = serialize($value);
             }
             $this->db->from('preferences');
             $this->db->where(array('name' => 'fs_balancer_ips'));
             if ($this->db->count_all_results() == 1) {
                 $this->db->update('preferences', array('value' => $value), array('name' => 'fs_balancer_ips'));
             } else {
                 $this->db->insert('preferences', array('name' => 'fs_balancer_ips', 'value' => $value));
             }
         }
         load_settings();
         set_notice('notice', _('Updated settings.'));
     }
     if (get_setting('fs_balancer_clients')) {
         $data["balancers"] = unserialize(get_setting('fs_balancer_clients'));
     } else {
         $data["balancers"] = array();
     }
     if (get_setting('fs_balancer_ips')) {
         $data["ips"] = unserialize(get_setting('fs_balancer_ips'));
     } else {
         $data["ips"] = array();
     }
     $this->viewdata['function_title'] = _('Balancers');
     $this->viewdata["main_content_view"] = $this->load->view("admin/loadbalancer/balancers_list.php", $data, TRUE);
     $this->load->view("admin/default.php", $this->viewdata);
 }
示例#9
0
	function teams($stub = "") {
		if ($stub == "") {
			$this->viewdata["function_title"] = "Team list";
			$teams = new Team();
			$teams->order_by('name', 'ASC')->get_iterated();
			$rows = array();
			foreach ($teams as $team) {
				$rows[] = array('title' => '<a href="' . site_url('admin/members/teams/' . $team->stub) . '">' . $team->name . '</a>');
			}
			$data['list'] = lister($rows);
			$this->viewdata["main_content_view"] = $this->load->view('admin/members/users', $data, TRUE);
			$this->load->view("admin/default", $this->viewdata);
		}
		else {
			$team = new Team();
			$team->where('stub', $stub)->get();

			if ($this->tank_auth->is_admin() || $this->tank_auth->is_group('mod'))
				$can_edit = true;
			else
				$can_edit = false;

			if ($this->tank_auth->is_team_leader($team->id) && !$can_edit)
				$can_edit_limited = true;
			else
				$can_edit_limited = false;

			if (($post = $this->input->post()) && ($can_edit || $can_edit_limited)) {
				$team = new Team();
				$team->where('stub', $stub)->get();
				$post["id"] = $team->id;
				if ($can_edit_limited) {
					unset($post['name']);
				}
				$team->update_team($post, TRUE);
				set_notice('notice', _('Saved.'));
			}


			$this->viewdata["function_title"] = "Team";
			$this->viewdata["extra_title"][] = $team->name;

			if ($can_edit_limited)
				$team->validation['name']['disabled'] = 'true';

			$result = ormer($team);

			$result = tabler($result, TRUE, ($can_edit || $can_edit_limited));
			$data['table'] = $result;
			$data['team'] = $team;

			$members = new Membership();
			$users = $members->get_members($team->id);

			$users_arr = array();
			foreach ($users->all as $key => $item) {
				$users_arr[$key][] = '<a href="' . site_url('/admin/members/member/' . $item->id) . '">' . $item->username . '</a>';
				if ($can_edit)
					$users_arr[$key][] = $item->email;
				$users_arr[$key][] = $item->last_login;
				$users_arr[$key][] = ($item->is_leader) ? _('Leader') : _('Member');
				if ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed()) {
					$buttoner = array();
					$buttoner = array(
						'text' => _("Remove member"),
						'href' => site_url('/admin/members/reject_application/' . $team->id . '/' . $item->id),
						'plug' => _('Do you want to remove this team member?')
					);
				}
				$users_arr[$key][] = (isset($buttoner) && !empty($buttoner)) ? buttoner($buttoner) : '';
				if (!$item->is_leader && ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed())) {
					$buttoner = array();
					$buttoner = array(
						'text' => _("Make leader"),
						'href' => site_url('/admin/members/make_team_leader/' . $team->id . '/' . $item->id),
						'plug' => _('Do you want to make this user a team leader?')
					);
				}
				if ($item->is_leader && ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed())) {
					$buttoner = array();
					$buttoner = array(
						'text' => _("Remove leader"),
						'href' => site_url('/admin/members/remove_team_leader/' . $team->id . '/' . $item->id),
						'plug' => _('Do you want to remove this user from the team leadership?')
					);
				}
				$users_arr[$key][] = (isset($buttoner) && !empty($buttoner)) ? buttoner($buttoner) : '';
			}

			// Spawn the form for adding a team leader
			$data["no_leader"] = FALSE;
			if ($this->tank_auth->is_allowed())
				$data["no_leader"] = TRUE;

			$data['members'] = tabler($users_arr, TRUE, FALSE);

			$this->viewdata["main_content_view"] = $this->load->view('admin/members/team', $data, TRUE);
			$this->load->view("admin/default", $this->viewdata);
		}
	}
示例#10
0
	function advertising() {
		$this->viewdata["function_title"] = _("Advertising");

		$form = array();


		$form[] = array(
			_('Top banner'),
			array(
				'type' => 'textarea',
				'name' => 'fs_ads_top_banner',
				'help' => _('Insert the HTML provided by your advertiser'),
				'preferences' => 'fs_ads'
			)
		);

		$form[] = array(
			_('Reload every pageview?'),
			array(
				'type' => 'checkbox',
				'name' => 'fs_ads_top_banner_reload',
				'placeholder' => '',
				'preferences' => 'fs_ads',
				'help' => _('Reload the advertising. Useful for ProjectWonderful.com. Use it without violating the TOS of your advertiser.')
			)
		);


		$form[] = array(
			_('Active'),
			array(
				'type' => 'checkbox',
				'name' => 'fs_ads_top_banner_active',
				'placeholder' => '',
				'preferences' => 'fs_ads'
			)
		);

		$form[] = array(
			_('Right banner'),
			array(
				'type' => 'textarea',
				'name' => 'fs_ads_left_banner',
				'help' => _('Insert the HTML provided by your advertiser'),
				'preferences' => 'fs_ads'
			)
		);

		$form[] = array(
			_('Reload every pageview?'),
			array(
				'type' => 'checkbox',
				'name' => 'fs_ads_left_banner_reload',
				'placeholder' => '',
				'preferences' => 'fs_ads',
				'help' => _('Reload the advertising. Useful for ProjectWonderful.com. Use it without violating the TOS of your advertiser.')
			)
		);


		$form[] = array(
			_('Active'),
			array(
				'type' => 'checkbox',
				'name' => 'fs_ads_left_banner_active',
				'placeholder' => '',
				'preferences' => 'fs_ads'
			)
		);

		$form[] = array(
			_('Bottom banner'),
			array(
				'type' => 'textarea',
				'name' => 'fs_ads_bottom_banner',
				'help' => _('Insert the HTML provided by your advertiser'),
				'preferences' => 'fs_ads'
			)
		);

		$form[] = array(
			_('Reload every pageview?'),
			array(
				'type' => 'checkbox',
				'name' => 'fs_ads_bottom_banner_reload',
				'placeholder' => '',
				'preferences' => 'fs_ads',
				'help' => _('Reload the advertising. Useful for ProjectWonderful.com. Use it without violating the TOS of your advertiser.')
			)
		);


		$form[] = array(
			_('Active'),
			array(
				'type' => 'checkbox',
				'name' => 'fs_ads_bottom_banner_active',
				'placeholder' => '',
				'preferences' => 'fs_ads'
			)
		);

		if ($post = $this->input->post()) {
			$this->_submit($post, $form);

			$ad_before = '<!DOCTYPE html>
						<html>
						  <head>
							<title>FoOlSlide ads</title>
							<style>body{margin:0; padding:0; overflow:hidden;}</style>
							<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
						  </head>
						  <body>';
			$ad_after = '</body>
						</html>';

			$ads = array('fs_ads_top_banner' => 'ads_top.html', 'fs_ads_bottom_banner' => 'ads_bottom.html', 'fs_ads_left_banner' => 'ads_left.html');
			foreach ($ads as $ad => $adfile) {
				if (!write_file('./content/ads/' . $adfile, $ad_before . $this->input->post($ad) . $ad_after)) {
					log_message('error', 'preferences.php/advertising: couldn\'t update HTML files');
					set_notice('error', _('Couldn\'t save the advertising code in the HTML'));
				}
			}
		}

		$table = tabler($form, FALSE);

		$data['table'] = $table;


		$this->viewdata["main_content_view"] = $this->load->view("admin/preferences/general.php", $data, TRUE);
		$this->load->view("admin/default.php", $this->viewdata);
	}
示例#11
0
 function teams($stub = "")
 {
     // no team selected
     if ($stub == "") {
         // set subtitle
         $this->viewdata["function_title"] = _('Teams');
         // we can use get_iterated on teams
         $teams = new Team();
         // support filtering via search
         if ($this->input->post()) {
             $teams->ilike('name', $this->input->post('search'));
             $this->viewdata['extra_title'][] = _('Searching') . " : " . $this->input->post('search');
         }
         $teams->order_by('name', 'ASC')->get_iterated();
         $rows = array();
         // produce links for each team
         foreach ($teams as $team) {
             $rows[] = array('title' => '<a href="' . site_url('admin/members/teams/' . $team->stub) . '">' . $team->name . '</a>');
         }
         // put in a list the teams
         $data['form_title'] = _('Teams');
         $data['table'] = lister($rows);
         // print out
         $this->viewdata["main_content_view"] = $this->load->view('admin/members/users', $data, TRUE);
         $this->load->view("admin/default", $this->viewdata);
     } else {
         // team was selected, let's grab it and create a form for it
         $team = new Team();
         $team->where('stub', $stub)->get();
         // if the team was not found return 404
         if ($team->result_count() != 1) {
             show_404();
         }
         // if admin or mod allow full editing rights
         if ($this->tank_auth->is_allowed()) {
             $can_edit = true;
         } else {
             $can_edit = false;
         }
         // if it's a team leader, but not admin or mod, allow him to change data but not the team name
         if ($this->tank_auth->is_team_leader($team->id) && !$can_edit) {
             $can_edit_limited = true;
         } else {
             $can_edit_limited = false;
         }
         // if allowed in any way to edit,
         if (($post = $this->input->post()) && ($can_edit || $can_edit_limited)) {
             $post["id"] = $team->id;
             // save the stub in case it's changed
             $old_stub = $team->stub;
             // don't allow editing of name for team leaders
             if ($can_edit_limited) {
                 unset($post['name']);
             }
             // send the data to database
             $team->update_team($post);
             // green box to tell data is saved
             set_notice('notice', _('Saved.'));
             if ($team->stub != $old_stub) {
                 flash_notice('notice', _('Saved.'));
                 redirect('admin/members/teams/' . $team->stub);
             }
         }
         // subtitle
         $this->viewdata["function_title"] = '<a href="' . site_url("admin/members/teams") . '">' . _('Teams') . '</a>';
         // subsubtitle!
         $this->viewdata["extra_title"][] = $team->name;
         // gray out the name field for team leaders by editing directly the validation array
         if ($can_edit_limited) {
             $team->validation['name']['disabled'] = 'true';
         }
         // convert the team information to an array
         $result = ormer($team);
         // convert the array to a form
         $result = tabler($result, TRUE, $can_edit || $can_edit_limited);
         $data['table'] = $result;
         $data['team'] = $team;
         // get the team's members
         $members = new Membership();
         $users = $members->get_members($team->id);
         // the team members' array needs lots of buttons and links
         $users_arr = array();
         foreach ($users->all as $key => $item) {
             $users_arr[$key][] = '<a href="' . site_url('/admin/members/member/' . $item->id) . '">' . $item->username . '</a>';
             // show the email only to admins and mods
             if ($can_edit) {
                 $users_arr[$key][] = $item->email;
             }
             $users_arr[$key][] = $item->last_login;
             // leader of normal member?
             $users_arr[$key][] = $item->is_leader ? _('Leader') : _('Member');
             if ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed()) {
                 $buttoner = array();
                 $buttoner = array('text' => _("Remove member"), 'href' => site_url('/admin/members/reject_application/' . $team->id . '/' . $item->id), 'plug' => _('Do you want to remove this team member?'));
             }
             // add button to array or stay silent if there's no button
             $users_arr[$key]['action'] = isset($buttoner) && !empty($buttoner) ? buttoner($buttoner) : '';
             if (!$item->is_leader && ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed())) {
                 $buttoner = array();
                 $buttoner = array('text' => _("Make leader"), 'href' => site_url('/admin/members/make_team_leader/' . $team->id . '/' . $item->id), 'plug' => _('Do you want to make this user a team leader?'));
             }
             if ($item->is_leader && ($this->tank_auth->is_team_leader($team->id) || $this->tank_auth->is_allowed())) {
                 $buttoner = array();
                 $buttoner = array('text' => _("Remove leader"), 'href' => site_url('/admin/members/remove_team_leader/' . $team->id . '/' . $item->id), 'plug' => _('Do you want to remove this user from the team leadership?'));
             }
             // add button to array or stay silent if there's no button
             $users_arr[$key]['action'] .= isset($buttoner) && !empty($buttoner) ? buttoner($buttoner) : '';
         }
         // Spawn the form for adding a team leader
         $data["no_leader"] = FALSE;
         if ($this->tank_auth->is_allowed()) {
             $data["no_leader"] = TRUE;
         }
         // make a form out of the array of members
         $data['members'] = tabler($users_arr, TRUE, FALSE);
         // print out
         $this->viewdata["main_content_view"] = $this->load->view('admin/members/team', $data, TRUE);
         $this->load->view("admin/default", $this->viewdata);
     }
 }
示例#12
0
 public function edit_acticle()
 {
     if (null != $this->input->post('edit_acticle_btn')) {
         $data_post = $this->input->post();
         $this->load->helper('Validation');
         $this->load->helper('HTMLPurifier');
         $config = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($config);
         $id = $data_post['acticle_id'];
         $data_update['acticle_name'] = $purifier->purify($data_post['acticle_name']);
         $data_update['acticle_content'] = $purifier->purify($data_post['acticle_content']);
         // $data_update['acticle_content'] = trim_input($data_update['acticle_content']);
         if ($this->Acticle->update($id, $data_update)) {
             $content = 'Cập nhật bài viết thành công.';
             set_notice('status', SUCCESS_STATUS, $content);
             header('location:' . base_url() . 'index.php/_admin/acticle/show_acticle');
         } else {
             $content = 'Cập nhật bài viết thất bại.';
             set_notice('status', FAILED_STATUS, $content);
             header('location:' . base_url() . 'index.php/_admin/acticle/show_acticle');
         }
     } else {
         if (null !== $this->uri->segment(4) && is_numeric($this->uri->segment(4)) && $this->Acticle->has_acticle_exist_by_id($this->uri->segment(4))) {
             $acticle_id = $this->uri->segment(4);
             $data['acticle_info'] = $this->Acticle->get_acticle_info($acticle_id);
             $data['subView'] = '/acticle/edit_acticle_layout';
             $data['title'] = "Chỉnh sửa bài viết";
             $data['subData'] = $data;
             $this->load->view('/main/main_layout', $data);
         } else {
             $data['pre_page'] = base_url() . 'index.php/_admin/acticle/show_acticle';
             $this->load->view('/error/404_layout', $data);
         }
     }
 }
示例#13
0
 function check($repair = FALSE)
 {
     // make sure we got the comic
     if ($this->get_comic() === FALSE) {
         $errors[] = 'chapter_comic_entry_not_found';
         set_notice('warning', _('Found a chapter entry without a comic entry, Chapter ID: ' . $this->id));
         log_message('debug', 'check: chapter entry without comic entry');
         if ($repair) {
             $this->remove_chapter_db();
         }
         return FALSE;
     }
     $errors = array();
     // check if the directory exists at all
     $path = 'content/comics/' . $this->comic->directory() . '/' . $this->directory() . '/';
     if (!is_dir($path)) {
         $errors[] = 'chapter_directory_not_found';
         set_notice('warning', _('No directory found for:') . ' ' . $this->comic->name . ' > ' . $this->title());
         log_message('debug', 'check: chapter directory missing at ' . $path);
         // the folder doesn't exist, so get rid of the entry from database
         if ($repair) {
             $this->remove_chapter_db();
         }
         // there's no recovery from this, return the error codes
         return $errors;
     }
     // check if there are extraneous files in the folder
     $files = get_dir_file_info($path);
     foreach ($files as $key => $file) {
         // check that the file is writable
         if (!is_writable($file['relative_path'])) {
             // non writable files are horrendous, send a notice and stop the machines
             $errors[] = 'chapter_non_writable_file';
             set_notice('warning', _('Found non writable files in the comics folder. Check your files permissions.'));
             log_message('debug', 'check: non writable file: ' . $file['relative_path']);
             return $errors;
         }
         // get the extension
         $ext = strtolower(substr($file['name'], -4));
         if (in_array($ext, array('.zip'))) {
             // maybe it's just the zip created by the archive system
             $archives = new Archive();
             $archives->where('comic_id', $this->comic_id)->where('chapter_id', $this->id)->where('volume_id', 0)->get();
             if ($archives->result_count()) {
                 foreach ($archives as $archive) {
                     // we actually have an archive, but is it the same file?
                     if ($file['name'] == $archive->filename) {
                         // same file, unset to confirm
                         unset($files[$key]);
                         continue;
                     }
                 }
             }
         }
         if (in_array($ext, array('.png', '.jpg', 'jpeg', '.gif'))) {
             $page = new Page();
             $page->where('chapter_id', $this->id)->where('filename', $file['name'])->get();
             if ($page->result_count() == 1) {
                 // it's a simple page, unset to confirm
                 unset($files[$key]);
                 continue;
             }
         }
     }
     // now we have an array with files that don't belong here
     foreach ($files as $file) {
         $errors[] = 'chapter_unidentified_file';
         set_notice('warning', _('Unidentified file found in:') . ' ' . $this->comic->name . ' > ' . $this->title() . ': ' . $file['name']);
         log_message('debug', 'check: unidentified file ' . $file['relative_path'] . $file['name']);
         // repairing this means getting rid of extraneous files
         if ($repair) {
             // it's possible the file is not removeable
             if (is_writable($file['relative_path'] . $file['name'])) {
                 // the files SHOULD be writable, we checked it earlier
                 if (is_dir($file['relative_path'] . $file['name'])) {
                     delete_files($file['relative_path'] . $file['name']);
                     rmdir($file['relative_path'] . $file['name']);
                 } else {
                     unlink($file['relative_path'] . $file['name']);
                 }
             }
         }
     }
     // everything's been checked. The errors are in the set_notice system
     return $errors;
 }
示例#14
0
	function _check() {
		$prob = FALSE;

		if (!file_exists('assets/config.sample.php')) {
			set_notice('error', sprintf(_('The file %s was removed. The installation can\'t continue without that file. You can find it in the FoOlSlide download.'), FCPATH . 'config.sample.php'));
			$prob = TRUE;
			return FALSE;
		}

		if (!is_writable('content')) {
			set_notice('error', sprintf(_('The %s directory needs to be writable. Use this command in your shell if possible: %s or change its permissions recursively to 777 with your own FTP software. You won\'t be able to install or run FoOlSlide without this.'), FCPATH . 'content/', '<br/><b><code>chmod -R 777 ' . FCPATH . 'content/</code></b><br/>'));
			$prob = TRUE;
			return FALSE;
		}

		if (!is_writable('content/themes')) {
			set_notice('error', sprintf(_('The %s directory needs to be writable as well. Use this command in your shell if possible: %s or change its permissions recursively to 777 with your own FTP software. You won\'t be able to install or run FoOlSlide without this.'), FCPATH . 'content/themes', '<br/><b><code>chmod -R 777 ' . FCPATH . 'content/</code></b><br/>'));
			$prob = TRUE;
			return FALSE;
		}

		if (!is_writable('.')) {
			$whoami = FALSE;
			if ($this->_exec_enabled())
				$whoami = exec('whoami');
			if (!$whoami && is_writable('content') && function_exists('posix_getpwid')) {
				write_file('content/testing_123.txt', 'testing_123');
				$whoami = posix_getpwuid(fileowner('content/testing_123.txt'));
				$whoami = $whoami['name'];
				unlink('content/testing_123.txt');
			}
			if ($whoami != "")
				set_notice('warn', sprintf(_('The %s directory would be better if writable, in order to deliver automatic updates. Use this command in your shell if possible: %s'), FCPATH, '<br/><b><code>chown -R ' . $whoami . ' ' . FCPATH . '</code></b>'));
			else
				set_notice('warn', sprintf(_('The %s directory would be better if writable, in order to deliver automatic updates.<br/>It was impossible to determine the user running PHP. Use this command in your shell if possible: %s where www-data is an example (usually it\'s www-data or Apache)'), FCPATH, '<br/><b><code>chown -R www-data ' . FCPATH . '</code></b><br/>'));
			set_notice('warn', sprintf(_('If you can\'t do the above, after the installation you will be given a textfile to paste in config.php. More info after submitting.')));
			$prob = TRUE;
		}

		if ($prob) {
			set_notice('notice', 'If you made any changes, just refresh this page to recheck the directory permissions.');
		}

		return TRUE;
	}
示例#15
0
 * @Since 1.0.0
 * @copyright  Copyright (C) 2011 5Twenty Studios
 * 
 */
defined('ABSPATH') or die("Cannot access pages directly.");
//initializing
$user = FiveTable::getInstance('user');
if (BRequest::getVar('verify', false)) {
    // LOGIN USER
    mysql_query("update user set status='active' where secToken='" . BRequest::getVar('verify', false) . "'") or die(mysql_error());
    $result = mysql_query("select id,username,email,zip from user where secToken='" . BRequest::getVar('verify', false) . "'") or die(mysql_error());
    $row = mysql_fetch_row($result);
    set_session($row[0], stripslashes($row[1]), stripslashes($row[2]), $row[3]);
    $user->load(get_current_user_id());
    set_notice('Please make sure to update your password before continuing.');
}
//redirect if successful
if (!is_user_logged_in()) {
    redirect(Router::url(array('controller' => 'user', 'action' => 'login')));
}
//loading the user
$user->load(get_current_user_id());
if ($post = BRequest::get('post', false)) {
    //$user->load( get_current_user_id() );
    if ($user->save($post)) {
        set_notice("Profile Saved.");
    } else {
        set_error($user->getErrors());
    }
}
require $view;
示例#16
0
 public function folder_chapter($cachedir, $chapter)
 {
     // Get the filename
     $dirarray = get_dir_file_info($cachedir, FALSE);
     $this->db->reconnect();
     $pages_added = array();
     foreach ($dirarray as $key => $value) {
         $extentsion = "";
         $extension = pathinfo($value["server_path"], PATHINFO_EXTENSION);
         if ($extension && !in_array(strtolower($extension), array('jpeg', 'jpg', 'png', 'gif'))) {
             continue;
         }
         $page = new Page();
         $error = false;
         if (!$page->add_page($value['server_path'], $value['name'], $chapter->id)) {
             log_message('error', 'compressed_chapter: one page in the loop failed being added');
             $error = true;
         }
         if ($error) {
             set_notice('error', 'Some pages weren\'t uploaded');
         }
         $pages_added[] = $page->get_clone();
     }
     return $pages_added;
 }
示例#17
0
	public function download($comic, $language = 'en', $volume = 0, $chapter = "", $subchapter = 0, $team = 0, $joint = 0, $pagetext = 'page', $page = 1) {
		if(!get_setting('fs_dl_enabled'))
			show_404();
		$comice = new Comic();
		$comice->where('stub', $comic)->get();
		if ($comice->result_count() == 0) {
			set_notice('warn', 'This comic doesn\'t exist.');
		}

		if ($chapter == "") {
			redirect('/reader/comic/' . $comic);
		}

		$chaptere = new Chapter();
		$chaptere->where('comic_id', $comice->id)->where('language', $language)->where('volume', $volume)->where('chapter', $chapter)->order_by('subchapter', 'ASC');

		if (!is_int($subchapter) && $subchapter == 'page') {
			$current_page = $team;
		}
		else {
			$chaptere->where('subchapter', $subchapter);

			if ($team == 'page')
				$current_page = $joint;
			else {
				if ($team != 0) {
					$teame = new Team();
					$teame->where('stub', $team)->get();
					$chaptere->where('team_id', $teame->id);
				}

				if ($joint == 'page')
					$current_page = $pagetext;

				if ($joint != 0) {
					$chaptere->where('joint_id', $joint);
				}
			}
		}

		if (!isset($current_page)) {
			if ($page != 1)
				$current_page = $page;
			else
				$current_page = 1;
		}

		$chaptere->get();
		if ($chaptere->result_count() == 0) {
			show_404();
		}
		
		$archive = new Archive();
		$url = $archive->compress($chaptere);
		redirect($url);
	}
示例#18
0
 public function edit_account()
 {
     if (null != $this->input->post('edit_account_btn')) {
         $data_post = $this->input->post();
         $this->load->helper('Validation');
         $this->load->helper('HTMLPurifier');
         $config = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($config);
         //====================== Validate  ======================
         $error = array();
         if (empty($_POST["username"])) {
             $error[] = "Username không được rỗng";
         } else {
             if ((preg_match('/^[A-Za-z0-9_\\.]{4,30}$/', $_POST["username"], $maches) || preg_match('/^[A-Za-z0-9_\\.]{4,30}$/', $_POST["username"], $maches)) && (strlen($_POST["username"]) >= 4 && strlen($_POST["username"]) <= 30)) {
                 $username = $_POST["username"];
                 $username = trim_input(trim($_POST["username"]));
                 $username_exist = $this->Account->check_username_exist($username, $data_post['id']);
                 if ($username_exist) {
                     $error[] = "Username đã tồn tại";
                 }
             } else {
                 $error[] = "Username gồm kí tự a-Z và có độ dài 4 - 30";
             }
         }
         $regex = "/^[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z]+\$/";
         if (empty($_POST["email"])) {
             $error[] = "Email không được rỗng!";
         } elseif (preg_match($regex, $_POST["email"], $maches)) {
             $insert_data['email'] = $_POST["email"];
         } else {
             $error[] = "Email không hợp lệ!";
         }
         if ($_POST['password'] != '' && strlen($_POST['password']) < 4) {
             $error[] = "Password phải nhiều hơn hoặc bằng 4 kí tự!";
         }
         if ($data_post['password'] != '') {
             if (strlen($_POST['password']) < 4 || strlen($_POST['password']) > 32) {
                 $error[] = "Password từ 4 đến 32 kí tự!";
             } else {
                 $data_update['password'] = md5($data_post['password']);
             }
         }
         if (!empty($_FILES['avatar']['name'])) {
             $avatar_name = $_FILES['avatar']['name'];
             $tmp = new SplFileInfo($avatar_name);
             $avatar_type = $tmp->getExtension();
             if (strtolower($avatar_type) != 'jpg' && strtolower($avatar_type) != 'gif' && strtolower($avatar_type) != 'png') {
                 $error[] = "Định dạng ảnh đại diện sản phẩm không cho phép!";
             } elseif (!isImage($_FILES['avatar']['tmp_name'])) {
                 $error[] = "Ảnh đại diện sản phẩm không phải là file ảnh!";
             } elseif ($_FILES['avatar']['size'] > 2048000) {
                 $error[] = "Ảnh đại diện sản phẩm phải nhỏ hơn 2MB";
             } else {
                 $tmp_name_avatar = $_FILES['avatar']['tmp_name'];
                 $data_update['avatar'] = md5($_POST["username"]) . '-' . time() . '.' . $avatar_type;
             }
         }
         //====================== Validate  ======================
         if (count($error) > 0) {
             $redata['re_id'] = $_POST['id'];
             $redata['re_username'] = $_POST['username'];
             $redata['re_email'] = $_POST['email'];
             $redata['avatar'] = $this->Account->get_avatar_by_id($_POST['id']);
             $alert_time = 20000;
             set_notice('status', FAILED_STATUS, $error, $alert_time);
             $data['subData'] = $redata;
             $data['title'] = "Cập nhật tài khoản";
             $data['subView'] = '/account/edit_account_layout';
             $this->load->view('/main/main_layout', $data);
         } else {
             $id = $data_post['id'];
             $data_update['username'] = $purifier->purify($data_post['username']);
             $data_update['email'] = $data_post['email'];
             $old_avatar = $this->Account->get_avatar_by_id($id);
             $rs = $this->Account->update($id, $data_update);
             if (rs) {
                 // ============= Upload anh avatar ===================
                 if ($rs && isset($_FILES['avatar'])) {
                     $path = "public/img/avatar/";
                     if (move_uploaded_file($tmp_name_avatar, $path . $data_update['avatar'])) {
                         resizeImage($path . $data_update['avatar'], $path . $data_update['avatar'], 600, 600);
                         @unlink($path . $old_avatar);
                     }
                 }
                 // ============= Upload anh avatar ===================
                 $this->load->model('Login_model', 'Login');
                 $user = $this->Login->getInfo($username);
                 $_SESSION['user'] = $user;
                 $content = 'Cập nhật tài khoản thành công.';
                 set_notice('status', SUCCESS_STATUS, $content);
                 header('location:' . base_url() . 'index.php/_admin/order/show_order');
             } else {
                 $content = 'Cập nhật tài khoản thất bại.';
                 set_notice('status', FAILED_STATUS, $content);
                 header('location:' . base_url() . 'index.php/_admin/order/show_order');
             }
         }
     } else {
         if (null !== $this->uri->segment(4) && is_numeric($this->uri->segment(4)) && $this->Account->has_account_exist_by_id($this->uri->segment(4))) {
             $account_id = $this->uri->segment(4);
             $data['account_info'] = $this->Account->get_account_info($account_id);
             $data['subView'] = '/account/edit_account_layout';
             $data['title'] = "Cập nhật tài khoản";
             $data['subData'] = $data;
             $this->load->view('/main/main_layout', $data);
         } else {
             $data['pre_page'] = base_url() . 'index.php/_admin/acticle/show_account';
             $this->load->view('/error/404_layout', $data);
         }
     }
 }
示例#19
0
 function import($stub)
 {
     if (!$this->tank_auth->is_admin()) {
         show_404();
     }
     if (!$stub) {
         show_404();
     }
     $comic = new Comic();
     $comic->where('stub', $stub)->get();
     $data['comic'] = $comic;
     $this->viewdata["extra_title"][] = $comic->name;
     $archive[] = array(_("Absolute directory path to ZIP archive for the series") . ' ' . $comic->name, array('type' => 'input', 'name' => 'directory', 'help' => sprintf(_('Insert the absolute directory path. This means from the lowest accessible directory. Example: %s'), '/var/www/backup/' . $comic->stub)));
     $data['archive'] = tabler($archive, FALSE, TRUE, TRUE);
     $this->viewdata["function_title"] = _("Import");
     if ($this->input->post('directory')) {
         $data['directory'] = $this->input->post('directory');
         if (!is_dir($data['directory'])) {
             set_notice('error', _('The directory you set does not exist.'));
             $this->viewdata["main_content_view"] = $this->load->view("admin/series/import", $data, TRUE);
             $this->load->view("admin/default.php", $this->viewdata);
             return FALSE;
         }
         $data['archives'] = $this->files_model->import_list($data);
         $this->viewdata["main_content_view"] = $this->load->view("admin/series/import_compressed_list", $data, TRUE);
         $this->load->view("admin/default.php", $this->viewdata);
         return TRUE;
     }
     if ($this->input->post('action') == 'execute') {
         $result = $this->files_model->import_compressed();
         if (isset($result['error']) && !$result['error']) {
             $this->output->set_output(json_encode($result));
             return FALSE;
         } else {
             $this->output->set_output(json_encode($result));
             return true;
         }
     }
     $this->viewdata["main_content_view"] = $this->load->view("admin/series/import", $data, TRUE);
     $this->load->view("admin/default.php", $this->viewdata);
 }
示例#20
0
/**
 * Displays the errors in a user friendly box
 */
function show_notifications()
{
    $errors = set_notice();
    if (!empty($errors)) {
        $errors = implode('<br/>', $errors);
        show_view('five-notification-success', array('notification' => $errors));
    }
}
示例#21
0
 public function doedit()
 {
     if (isset($_POST["btnSubmit"])) {
         //============================== Purifier ==============================
         $this->load->helper('Validation');
         $this->load->helper('HTMLPurifier');
         $config = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($config);
         // $clean_html = $purifier->purify($dirty_html); //su dung
         //============================== Purifier ==============================
         $update_data = array();
         $war = array();
         $loi = array();
         $has_new_detail_image = false;
         $product_id = $_POST['product_id'];
         $page = isset($_POST['page']) && is_numeric($_POST['page']) ? $_POST['page'] : 1;
         $old_detail_image = $this->Product->get_detail_image($product_id);
         $old_avatar = $this->Product->get_avatar($product_id);
         $delete_detail_img = empty($_POST['delete_detail_img']) ? array() : $_POST['delete_detail_img'];
         if (count($_FILES['detail_img']['name']) > 0) {
             $imgs = $_FILES['detail_img'];
             $url = '';
             $tmp_name_detail_img = array();
             for ($i = 0; $i < count($_FILES['detail_img']['name']); $i++) {
                 if ($_FILES['detail_img']['name'][$i] != '') {
                     $tmp = new SplFileInfo($_FILES['detail_img']['name'][$i]);
                     $type = $tmp->getExtension();
                     if (strtolower($type) != 'jpg' && strtolower($type) != 'gif' && strtolower($type) != 'png') {
                         $war[] = "Dịnh dạng ảnh chi tiết sản phẩm không cho phép!";
                         $type = $tmp->getExtension();
                     } elseif ($_FILES['detail_img']['size'][$i] > 1024000) {
                         $war[] = "Ảnh chi tiết sản phẩm phải nhỏ hơn 2MB";
                     } elseif (!isImage($_FILES['detail_img']['tmp_name'][$i])) {
                         $war[] = "Ảnh chi tiết không phải là file ảnh!";
                     } else {
                         $url = $url . '|' . htmlspecialchars(md5($_POST['product_name'])) . '-' . $i . time() . '.' . $type;
                         $tmp_name_detail_img[] = $_FILES['detail_img']['tmp_name'][$i];
                     }
                 }
             }
             if (trim($url, '|') != '') {
                 $new_detail_image = trim($url, '|');
                 $update_data['detail_image'] = $old_detail_image . '|' . $new_detail_image;
                 $update_data['detail_image'] = trim($update_data['detail_image'], '|');
                 $has_new_detail_image = true;
             }
         }
         if (!empty($delete_detail_img)) {
             if ($has_new_detail_image) {
                 foreach ($delete_detail_img as $value) {
                     $update_data['detail_image'] = str_replace($value . '|', '', $update_data['detail_image']);
                 }
             } else {
                 $update_data['detail_image'] = $old_detail_image . '|';
                 foreach ($delete_detail_img as $value) {
                     $update_data['detail_image'] = str_replace($value . '|', '', $update_data['detail_image']);
                 }
             }
             $update_data['detail_image'] = trim($update_data['detail_image'], '|');
         }
         $update_data['product_name'] = trim_input($_POST["product_name"]);
         $update_data['category_id'] = $_POST["category_id"];
         $update_data['des'] = $purifier->purify($_POST["des"]);
         $update_data['price'] = trim_input($_POST["price"]);
         $update_data['size'] = $purifier->purify($_POST["size"]);
         $update_data['substance'] = $purifier->purify($_POST["substance"]);
         //====================== Validate START ======================
         if (!empty($_FILES['avatar']['name'])) {
             $avatar_name = $_FILES['avatar']['name'];
             $tmp = new SplFileInfo($avatar_name);
             $avatar_type = $tmp->getExtension();
             if (strtolower($avatar_type) != 'jpg' && strtolower($avatar_type) != 'gif' && strtolower($avatar_type) != 'png') {
                 $loi[] = "Định dạng ảnh đại diện sản phẩm không cho phép!";
             } elseif (!isImage($_FILES['avatar']['tmp_name'])) {
                 $loi[] = "Ảnh đại diện sản phẩm không phải là file ảnh!";
             } elseif ($_FILES['avatar']['size'] > 2048000) {
                 $loi[] = "Ảnh đại diện sản phẩm phải nhỏ hơn 2MB";
             } else {
                 $tmp_name_avatar = $_FILES['avatar']['tmp_name'];
                 $update_data['image'] = md5($update_data['product_name']) . '-' . time() . '.' . $avatar_type;
             }
         }
         if (empty($_POST["product_name"])) {
             $loi[] = "Tên sản phẩm không được rỗng";
         } elseif (strip_tags($_POST["product_name"]) == '') {
             $loi[] = "Tên sản phẩm không hợp lệ!";
         } else {
             if (strlen($_POST["product_name"]) >= 4 && strlen($_POST["product_name"]) <= 100) {
                 $update_data['product_name'] = $_POST["product_name"];
                 $update_data['product_name'] = trim($_POST["product_name"]);
                 $update_data['product_name'] = strip_tags($_POST["product_name"]);
                 $update_data['product_name'] = addslashes($update_data['product_name']);
                 $product_name_exist = $this->Product->has_exist_product_name($update_data['product_name'], $product_id);
                 if ($product_name_exist) {
                     $loi[] = "Sản phẩm đã tồn tại";
                 }
             } else {
                 $loi[] = "Tên sản phẩm phải dài hơn 4 và nhỏ hơn 100 kí tự!";
             }
         }
         if (empty($update_data['category_id'])) {
             $loi[] = "Chưa chọn loại sản phẩm!";
         } elseif (!is_numeric($update_data['category_id']) || !$this->Category->has_sub_category_exist_by_id($update_data['category_id'])) {
             $loi[] = "Loại sản phẩm không hợp lệ!";
         }
         if (!empty($update_data['price'])) {
             if (!is_numeric($update_data['price'])) {
                 $loi[] = "Giá phải là kiểu số!";
             }
         }
         //====================== Validate END ======================
         if (count($loi) > 0) {
             $alert_time = 20000;
             set_notice(FAILED_STATUS, $loi, $alert_time);
             $data['category'] = $this->Category->list_all_sub_category();
             $redata['info'] = $this->Product->get_product_by_id($product_id);
             $redata['re_product_name'] = $_POST['product_name'];
             $redata['re_category_id'] = $_POST['category_id'];
             $redata['re_price'] = $_POST['price'];
             $redata['re_size'] = $_POST['size'];
             $redata['re_substance'] = $_POST['substance'];
             $redata['re_des'] = $_POST['des'];
             $redata['re_page'] = $page;
             $data['subView'] = '/product/edit_product_layout';
             $data['title'] = 'Cập nhật sản phẩm';
             $data['subData'] = $redata;
             $this->load->view('/main/main_layout', $data);
         } else {
             $rs = $this->Product->update($product_id, $update_data);
             // ============= Xoa anh chi tiet ===================
             if ($rs && !empty($delete_detail_img)) {
                 foreach ($delete_detail_img as $value) {
                     @unlink('public/img/detail_img/' . $value);
                 }
             }
             // ============= Xoa anh chi tiet ===================
             // ============= Upload anh chi tiet ===================
             if ($rs && $has_new_detail_image) {
                 $detail_image_name = explode('|', $new_detail_image);
                 for ($i = 0; $i < count($detail_image_name); $i++) {
                     $path = "public/img/detail_img/";
                     move_uploaded_file($tmp_name_detail_img[$i], $path . $detail_image_name[$i]);
                     resizeImage($path . $detail_image_name[$i], $path . $detail_image_name[$i], 600, 600);
                 }
             }
             // ============= Upload anh chi tiet ===================
             // ============= Upload anh avatar ===================
             if ($rs && isset($_FILES['avatar'])) {
                 $path = "public/img/products/";
                 if (move_uploaded_file($tmp_name_avatar, $path . $update_data['image'])) {
                     resizeImage($path . $update_data['image'], $path . $update_data['image'], 600, 600);
                     @unlink('public/img/products/' . $old_avatar);
                 }
             }
             // ============= Upload anh avatar ===================
             if ($rs) {
                 if (!empty($war)) {
                     $war['title'] = 'Cập nhật sản phẩm <span style="color:blue;"> ' . $update_data['product_name'] . '</span> thành công!';
                     $content = $war;
                     $alert_time = 15000;
                     set_notice(FAILED_STATUS, $content, $alert_time);
                     header('location:' . base_url() . 'index.php/_admin/product');
                 } else {
                     $mess = 'Cập nhật sản phẩm <span style="color:blue;"> ' . $update_data['product_name'] . '</span> thành công!';
                     set_notice(SUCCESS_STATUS, $mess);
                     header('location:' . base_url() . 'index.php/_admin/product');
                 }
             } else {
                 $mess = 'Có lỗi xảy ra cập nhật sản phẩm.';
                 set_notice(FAILED_STATUS, $mess);
                 header('location:' . base_url() . 'index.php/_admin/product/add_product');
             }
         }
     }
 }
示例#22
0
 public function rebuild_thumbnail()
 {
     // Let's make sure the chapter and comic is set
     $this->get_chapter();
     $path = "content/comics/" . $this->chapter->comic->directory() . "/" . $this->chapter->directory() . "/" . $this->filename;
     // get paths and remove the thumb
     if (!file_exists($path)) {
         set_notice('warning', _('Page not found while creating thumbnail:') . ' ' . $this->chapter->comic->name . ' > ' . $this->chapter->title());
         log_message('error', 'rebuild_thumbnail: there\'s a missing image in ' . $path);
         // don't stop the process
         return TRUE;
     }
     $thumb_path = "content/comics/" . $this->chapter->comic->directory() . "/" . $this->chapter->directory() . "/" . $this->thumbnail . $this->filename;
     if (file_exists($thumb_path)) {
         if (!unlink($thumb_path)) {
             set_notice('error', _('Failed to remove the thumbnail while rebuilding it. Please, check file permissions.'));
             log_message('error', 'rebuild_thumbnail: failed to remove thumbnail while rebuilding');
             return FALSE;
         }
     }
     // Prepare the image library to create the thumbnail
     $CI =& get_instance();
     $CI->load->library('image_lib');
     $img_config['image_library'] = find_imagick() ? 'ImageMagick' : 'GD2';
     // Use GD2 as fallback
     $img_config['library_path'] = find_imagick() ? get_setting('fs_serv_imagick_path') ? get_setting('fs_serv_imagick_path') : '/usr/bin' : '';
     // If GD2, use none
     $img_config['source_image'] = $path;
     $img_config["new_image"] = $thumb_path;
     $img_config['width'] = 250;
     $img_config['height'] = 250;
     $img_config['maintain_ratio'] = TRUE;
     $img_config['master_dim'] = 'auto';
     $CI->image_lib->initialize($img_config);
     // Resize to create the thumbnail
     if (!$CI->image_lib->resize()) {
         set_notice('error', _('Failed to recreate the thumbnail of the page.'));
         log_message('error', 'rebuild_thumbnail: failed to recreate thumbnail');
         return FALSE;
     }
     // update the kind of compression used and thumbnail filesize
     $this->thumbsize = filesize($thumb_path);
     $this->description = find_imagick() ? 'im' : '';
     if (!$this->save()) {
         set_notice('error', _('Failed to save the image compression method in the database.'));
         log_message('error', 'rebuild_thumbnail: failed to save the image compression method');
         return FALSE;
     }
     // Clear the image library for who knows who else calls it
     $CI->image_lib->clear();
     // Good
     return TRUE;
 }
示例#23
0
	function permissions_suggest() {
		if (!is_writable('.')) {
			$whoami = FALSE;
			if ($this->_exec_enabled())
				$whoami = exec('whoami');
			if (!$whoami && is_writable('content') && function_exists('posix_getpwid')) {
				write_file('content/testing_123.txt', 'testing_123');
				$whoami = posix_getpwuid(fileowner('content/testing_123.txt'));
				$whoami = $whoami['name'];
				unlink('content/testing_123.txt');
			}
			if ($whoami != "")
				set_notice('warn', sprintf(_('The %s directory would be better if writable, in order to deliver automatic updates. Use this command in your shell if possible: %s'), FCPATH, '<br/><b><code>chown -R ' . $whoami . ' ' . FCPATH . '</code></b>'));
			else
				set_notice('warn', sprintf(_('The %s directory would be better if writable, in order to deliver automatic updates.<br/>It was impossible to determine the user running PHP. Use this command in your shell if possible: %s where www-data is an example (usually it\'s www-data or Apache)'), FCPATH, '<br/><b><code>chown -R www-data ' . FCPATH . '</code></b><br/>'));
			set_notice('warn', sprintf(_('If you can\'t do the above, you can follow the manual upgrade instructons at %sthis link%s.'), '<a href="http://trac.foolrulez.com/foolslide/wiki/installation_guide#Manualupgradeorifautomaticupgradebrokeeverything">', '</a>'));
			$prob = TRUE;
		}

		if ($prob) {
			set_notice('notice', 'If you made any changes, just refresh this page to recheck the directory permissions.');
		}
	}
示例#24
0
 public function remove_team_from_all($team_id)
 {
     $joints = new Joint();
     $joints->where('team_id', $team_id)->get();
     if (!$joints->delete_all()) {
         set_notice('error', _('Couldn\'t remove the team from all the joints.'));
         log_message('error', 'remove_team_from_all (joint.php): removing failed');
         return false;
     }
 }
示例#25
0
 public function add_slider()
 {
     if (isset($_POST['edit_slider_btn'])) {
         $data_post = $this->input->post();
         $this->load->helper('Validation');
         $this->load->helper('HTMLPurifier');
         $config = HTMLPurifier_Config::createDefault();
         $purifier = new HTMLPurifier($config);
         //====================== Validate START ======================
         $error = array();
         $link_slider = array();
         for ($i = 0; $i < count($_FILES['image_slider']['name']); $i++) {
             $data_insert['link_slider'][$i] = '';
             if ($_FILES['image_slider']['name'][$i] != '') {
                 $tmp = new SplFileInfo($_FILES['image_slider']['name'][$i]);
                 $type = $tmp->getExtension();
                 if (strtolower($type) != 'jpg' && strtolower($type) != 'gif' && strtolower($type) != 'png') {
                     $error[] = "Không đúng định dạng ảnh cho phép!";
                 } elseif (!isImage($_FILES['image_slider']['tmp_name'][$i])) {
                     $error[] = "Không phải là file ảnh!";
                 } elseif ($_FILES['image_slider']['size'][$i] > 2048000) {
                     $error[] = "Ảnh lớn hơn 2MB";
                 } else {
                     $data_insert['link_slider'][$i] = $i . microtime() . '.' . $type;
                     $tmp_name_image_slider[$i] = $_FILES['image_slider']['tmp_name'][$i];
                 }
             } else {
                 $error[] = "Bắt buộc phải upload 1 ảnh cho 1 slide.";
             }
         }
         for ($i = 0; $i < count($data_post['des_slider']); $i++) {
             if ($data_post['des_slider'][$i] !== '') {
                 $data_insert['des_slider'][$i] = $purifier->purify($data_post['des_slider'][$i]);
             } else {
                 $data_insert['des_slider'][$i] = '';
             }
         }
         //====================== Validate END ======================
         if (count($error) > 0) {
             $alert_time = 15000;
             set_notice('status', FAILED_STATUS, $error, $alert_time);
             $redata['re_des_slider'] = $data_post['des_slider'];
             $data['subView'] = '/manage_site/slider/add_slider_layout';
             $data['title'] = "Thêm hình ảnh vào slider";
             $data['subData'] = $redata;
             $this->load->view('/main/main_layout', $data);
         } else {
             $tmp_insert = array();
             for ($i = 0; $i < count($data_post['des_slider']); $i++) {
                 // $this->Slider->insert($data_insert[]);
                 $tmp_insert['link_slider'] = $data_insert['link_slider'][$i];
                 $tmp_insert['des_slider'] = $data_insert['des_slider'][$i];
                 $tmp_rs = $this->Slider->insert($tmp_insert);
             }
             // ============= Upload anh image_slider ===================
             for ($i = 0; $i < count($_FILES['image_slider']['name']); $i++) {
                 if (!empty($_FILES['image_slider']['name'][$i])) {
                     $path = "public/img/slider/";
                     if (move_uploaded_file($tmp_name_image_slider[$i], $path . $data_insert['link_slider'][$i])) {
                         resizeImage($path . $data_insert['link_slider'][$i], $path . $data_insert['link_slider'][$i], 400, 400);
                     }
                 }
             }
             // ============= Upload anh image_slider ===================
             $content = 'Thêm mới slide thành công.';
             set_notice('status', SUCCESS_STATUS, $content);
             header('location:' . base_url() . 'index.php/_admin/manage_site/slider/show_slider');
         }
     } else {
         $data['subView'] = '/manage_site/slider/add_slider_layout';
         $data['title'] = "Thêm hình ảnh vào slider";
         $data['subData'] = $data;
         $this->load->view('/main/main_layout', $data);
     }
 }
示例#26
0
	/**
	 * Removes the chapter folder with all the data that was inside of it.
	 * This means pages and props too.
	 *
	 * @author	Woxxy
	 * @return	boolean true if success, false if failure.
	 */
	public function remove_chapter_dir() {
		// Get the comic if we didn't yet.
		if (!$this->get_comic()) {
			set_notice('error', _('No comic related to this chapter.'));
			log_message('error', 'remove_chapter_dir: comic did not exist');
			return false;
		}

		// Create the direcotry name
		$dir = "content/comics/" . $this->comic->directory() . "/" . $this->directory() . "/";

		// Delete all files inside of it
		if (!delete_files($dir, TRUE)) {
			set_notice('error', _('Failed to remove the files inside the chapter directory. Please, check file permissions.'));
			log_message('error', 'remove_chapter_dir: files inside folder could not be removed');
			return false;
		}
		else {
			// On success of emptying, remove the chapter directory itself.
			if (!rmdir($dir)) {
				set_notice('error', _('Failed to remove the chapter directory. Please, check file permissions.'));
				log_message('error', 'remove_chapter_dir: folder could not be removed');
				return false;
			}
		}

		return true;
	}
示例#27
0
文件: page.php 项目: Nakei/FoOlSlide
	/**
	 * Removes the image file and the thumbnail.
	 *
	 * @author	Woxxy
	 * @return	boolean true if success, false if failure.
	 */
	public function remove_page_file() {
		// Make sure chapter and comic are set
		$this->get_chapter();

		// Get the chapter directory
		$dir = "content/comics/" . $this->chapter->comic->directory() . "/" . $this->chapter->directory() . "/";

		// Remove the image
		if (!unlink($dir . $this->filename)) {
			set_notice('error', _('Failed to remove the page\'s file. Please, check file permissions.'));
			log_message('error', 'remove_page_file: failed to delete image');
			return false;
		}

		// Remove the thumbnail
		if (!unlink($dir . "thumb_" . $this->filename)) {
			set_notice('error', _('Failed to remove the page\'s thumbnail. Please, check file permissions.'));
			log_message('error', 'remove_page_file: failed to delete thumbnail');
			return false;
		}

		// Good
		return true;
	}
示例#28
0
 public function download($comic, $language = 'en', $volume = null, $chapter = null, $subchapter = 0)
 {
     if (!get_setting('fs_dl_enabled')) {
         show_404();
     }
     $comice = new Comic();
     $comice->where('stub', $comic)->get();
     if ($comice->result_count() == 0) {
         set_notice('warn', 'This comic does not exist.');
     }
     $archive = new Archive();
     $result = $archive->compress($comice, $language, $volume, $chapter, $subchapter);
     if ($this->input->is_cli_request()) {
         echo $result["server_path"] . PHP_EOL;
     } else {
         redirect($result["url"]);
     }
 }