PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website shop bán domain hosting PHP/admin/si/siEdit.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 279 lines | 193 code | 67 blank | 19 comment | 24 complexity | 4ce6368d87d4a00e09db9fcceb81d29d MD5 | raw file
  1. <?php
  2. /*----------------------------------------
  3. * EDIT SERVICE INFORMATION
  4. ------------------------------------------*/
  5. // Check for security
  6. if (!defined('HCR'))
  7. {
  8. print '<h1>Incorrect Access!</h1>';
  9. exit();
  10. }
  11. $cnt = new content;
  12. class content{
  13. public $title = 'Hiệu chỉnh thông tin giới thiệu dịch vụ';
  14. public $text = '';
  15. private $process = '';
  16. private $siID = '';
  17. private $frmValue = array(
  18. 'name' => '',
  19. 'intro' => '',
  20. 'content' => '',
  21. 'rank' => '',
  22. );
  23. private $file = array(
  24. 'name' => '',
  25. 'type' => '',
  26. 'size' => '',
  27. 'tmp' => ''
  28. );
  29. private $warning = '';
  30. private $err = '';
  31. function __construct()
  32. {
  33. global $str, $sess, $token;
  34. $this->siID = isset($_GET['id']) ? $_GET['id'] : 0;
  35. $this->get_input();
  36. $check_input = $this->check_input($this->frmValue);
  37. if ($this->process == "editSI")
  38. {
  39. if ($check_input)
  40. {
  41. $this->update_field($this->frmValue);
  42. if (isset($_GET['r']) && strlen($_GET['r']) > 0)
  43. {
  44. $str->goto_url(urldecode($_GET['r']));
  45. }
  46. $str->goto_url('?mod=siList');
  47. }
  48. else
  49. {
  50. $this->warning = "<b><u>Lỗi nhập liệu</u>:&nbsp;</b><span class='span_err'><ul>". $this->err ."</ul></span>";
  51. }
  52. }
  53. $this->text = ($this->warning) ? "<div id='warning'>" . $this->warning . "</div>" . $this->show_form($this->frmValue) : $this->show_form($this->frmValue);
  54. }
  55. /*---------------------------
  56. | SHOW FORM
  57. + ---------------------------
  58. */
  59. function show_form($frmValue)
  60. {
  61. global $frm, $db, $sess, $time;
  62. $query = $db->simple_select('*', 'service_intro', 'id = "'. $this->siID .'"');
  63. $result = $db->query($query);
  64. $row = $db->fetch_assoc($result);
  65. $text = '';
  66. // JS for lightbox
  67. $text = '<link rel="stylesheet" href="'. DIR_LIGHTBOX .'css/lightbox.css" type="text/css" media="screen" />
  68. <script src="'. DIR_LIGHTBOX .'js/prototype.js" type="text/javascript"></script>
  69. <script src="'. DIR_LIGHTBOX .'js/scriptaculous.js?load=effects" type="text/javascript"></script>
  70. <script src="'. DIR_LIGHTBOX .'js/lightbox.js" type="text/javascript"></script>';
  71. $text .= $frm->draw_form("", "", 2, "POST", "frm_editSI");
  72. $text .= $frm->draw_hidden("process", "editSI");
  73. $text .= '<table cellpadding="4" cellspacing="0" class="tbl_edit">';
  74. $text .= "<tr>";
  75. $text .= "<td>Tên dịch vụ : </td>";
  76. $text .= "<td>". $frm->draw_textfield("name", $frmValue["name"] ? $frmValue["name"] : $row['name'], "", "60", "255") ."</td>";
  77. $text .= "</tr>
  78. <tr><td colspan='2' height='6'></td></tr>";
  79. $text .= "<tr>";
  80. $text .= "<td>Thứ tự : </td>";
  81. $text .= "<td>". $frm->draw_textfield("rank", $frmValue["rank"] ? $frmValue["rank"] : $row['rank'], "", "10", "20") ."</td>";
  82. $text .= "</tr>
  83. <tr><td colspan='2' height='6'></td></tr>";
  84. $text .= "<tr>";
  85. $text .= "<td>Hình hiện tại : </td>";
  86. $image = $row['thumb'] ? "<a href='". SI_IMG . $row['thumb'] ."' rel='lightbox'><img src='". SI_IMG . $row['thumb'] ."' class='thumbnail' title='Nhấp để xem kích thước thật' /></a>" : "<font color='red'>Chưa có hình</font>";
  87. $text .= "<td>". $image ."</td>";
  88. $text .= "</tr>
  89. <tr><td colspan='2' height='6'></td></tr>";
  90. $text .= "<tr>";
  91. $text .= "<td>Đổi hình : </td>";
  92. $text .= "<td>". $frm->draw_file("file") ."&nbsp;<font color='#0000FF'>289x82 px</font>&nbsp;(*.jpg, *.gif, *.png & <=1MB)</td>
  93. </tr>
  94. <tr><td colspan='2' align='center'><font color='blue'>Nếu không muốn thay đổi,hãy để trống</font></td></tr>
  95. <tr><td colspan='2' height='6'></td></tr>";
  96. $text .= "<tr>";
  97. $text .= "<td>Giới thiệu : </td><td>";
  98. // Embed FCKEditor
  99. $oFCKeditor = new FCKeditor('intro');
  100. $oFCKeditor->BasePath = DIR_LIB_EDITOR;
  101. $oFCKeditor->Value = $frmValue['intro'] ? $frmValue['intro'] : $row['intro'];
  102. $oFCKeditor->Width = '650' ;
  103. $oFCKeditor->Height = '300' ;
  104. $text .= $oFCKeditor->Create() ."</td></tr>";
  105. $text .= "<tr><td colspan='2' height='6'></td></tr>";
  106. $text .= "<tr>";
  107. $text .= "<td>Nội dung : </td><td>";
  108. // Embed FCKEditor
  109. $oFCKeditor = new FCKeditor('content');
  110. $oFCKeditor->BasePath = DIR_LIB_EDITOR;
  111. $oFCKeditor->Value = $frmValue['content'] ? $frmValue['content'] : $row['content'];
  112. $oFCKeditor->Width = '650' ;
  113. $oFCKeditor->Height = '600' ;
  114. $text .= $oFCKeditor->Create() ."</td></tr>";
  115. $text .= "<tr><td colspan='2' height='6'></td></tr>";
  116. $text .= "<tr>";
  117. $text .= "<td colspan='2' align='center'>";
  118. $text .= $frm->draw_submit(" Cập nhật ", "");
  119. $text .= "&nbsp;&nbsp;<input type='reset' value=' Hủy '></td>";
  120. $text .= "</tr>";
  121. $text .= "</table>";
  122. $text .= "</form>";
  123. return $text;
  124. }
  125. /*-------------------------
  126. | GET INPUT DATA
  127. +--------------------------*/
  128. function get_input()
  129. {
  130. global $str;
  131. $this->process = isset($_POST['process']) ? $str->input($_POST['process']) : "";
  132. $this->frmValue['name'] = isset($_POST['name']) ? $str->input($_POST['name']) : "";
  133. $this->frmValue['intro'] = isset($_POST['intro']) ? $str->input_html($_POST['intro']) : "";
  134. $this->frmValue['content'] = isset($_POST['content']) ? $str->input_html($_POST['content']) : "";
  135. $this->frmValue['rank'] = isset($_POST['rank']) ? $str->input($_POST['rank']) : "";
  136. if (isset($_FILES['file']['name']))
  137. {
  138. $this->file['name'] = $_FILES['file']['name'];
  139. $this->file['type'] = $_FILES['file']['type'];
  140. $this->file['size'] = $_FILES['file']['size'];
  141. $this->file['tmp'] = $_FILES['file']['tmp_name'];
  142. }
  143. }
  144. /*----------------------------
  145. | CHECK FOR INPUT DATA
  146. +-----------------------------*/
  147. function check_input($frmValue)
  148. {
  149. global $frm, $str, $db;
  150. $no_error = true;
  151. if (!$frm->check_input($frmValue['name'], 1))
  152. {
  153. $no_error = false;
  154. $this->err .= '<li>Hãy nhập tên</li>';
  155. }
  156. if (!$frm->check_input($frmValue['intro'], 1))
  157. {
  158. $no_error = false;
  159. $this->err .= '<li>Hãy nhập giới thiệu</li>';
  160. }
  161. if (!$frm->check_input($frmValue['content'], 1))
  162. {
  163. $no_error = false;
  164. $this->err .= '<li>Hãy nhập nội dung</li>';
  165. }
  166. if ($this->file['name'])
  167. {
  168. if (!is_uploaded_file($this->file['tmp']))
  169. {
  170. $no_error = false;
  171. $this->err .= '<li>Lỗi trong quá trình upload ảnh lên server</li>';
  172. }
  173. if ( ( $this->file['type'] != "image/jpeg" ) && ( $this->file['type'] != "image/gif" ) && ( $this->file['type'] != "image/x-png" ) && ( $this->file['type'] != "image/pjpeg" ) && ( $this->file['type'] != "image/png" ) )
  174. {
  175. $no_error = false;
  176. $this->err .= '<li>Loại file ảnh không hợp lệ</li>';
  177. }
  178. if ($this->file['size'] > 1048576)
  179. {
  180. $no_error = false;
  181. $this->err .= '<li>Kích thước file quá lớn(<=1MB)</li>';
  182. }
  183. }
  184. return $no_error;
  185. }
  186. // UPDATE DATA TO DB
  187. function update_field($frmValue)
  188. {
  189. global $db, $time, $sess;
  190. $str_replace = array("á","à","ã","â","é","è","ê","í","ì","ý","ú","ù","ó","ò","õ","ô","Á","À","Ã","Â","É","È","Ê","Í","Ì","Ý","Ú","Ù","Ó","Ò","Õ","Ô");
  191. $str = array("&aacute;","&agrave;","&atilde;","&acirc;","&eacute;","&egrave;","&ecirc;","&iacute;","&igrave;","&yacute;","&uacute;","&ugrave;","&oacute;","&ograve;","&otilde;","&ocirc;","&Aacute;","&Agrave;","&Atilde;","&Acirc;","&Eacute;","&Egrave;","&Ecirc;","&Iacute;","&Igrave;","&Yacute;","&Uacute;","&Ugrave;","&Oacute;","&Ograve;","&Otilde;","&Ocirc;");
  192. $frmValue['intro'] = str_replace($str, $str_replace, $frmValue['intro']);
  193. $frmValue['content'] = str_replace($str, $str_replace, $frmValue['content']);
  194. $arr = array(
  195. 'name' => $frmValue['name'],
  196. 'intro' => $frmValue['intro'],
  197. 'content' => $frmValue['content'],
  198. 'rank' => $frmValue['rank']
  199. );
  200. if ($this->file['name'])
  201. {
  202. // Generate image name
  203. $img_name = rand(9,999999);
  204. $img_name .= '_'.$this->file['name'];
  205. $arr['thumb'] = $img_name;
  206. @move_uploaded_file( $this->file['tmp'], SI_IMG . $img_name );
  207. }
  208. $db->do_update("service_intro", $arr, "id = '". $this->siID ."'" );
  209. return true;
  210. }
  211. }
  212. ?>