PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/controller/user-show-autoinfo.php

https://gitlab.com/Chhorvan/autoexpresscambodia_mobile
PHP | 353 lines | 236 code | 72 blank | 45 comment | 37 complexity | 2a6d662d44fb7a429db9db60381ffff1 MD5 | raw file
Possible License(s): MIT, GPL-3.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. ################################################################################
  3. ### This disclaimer must be kept intact in order to use this product. ###
  4. ################################################################################
  5. ### Project: jT CarFramework [http://intersofts.com]
  6. ### Author: J. Toshio Taniguchi
  7. ### Since: 27.04.2011
  8. ### Version: 1.0.0
  9. ### Copyrights: J. Toshio Taniguchi
  10. ### Contact: j.taniguchi@taniguchi-blog.com
  11. ################################################################################
  12. ### CONTRIBUTORS
  13. ### - none
  14. ################################################################################
  15. include('resize-class.php');
  16. class userShowAutoinfo
  17. {
  18. protected $lang;
  19. protected $group = 'public';
  20. protected $slug = 'car';
  21. protected $form_status;
  22. protected $form_message;
  23. Protected $status="";
  24. protected $form_style;
  25. private $url="";
  26. /*
  27. * Constructor -------------------------------------------------------------
  28. */
  29. public function userShowAutoinfo($lang=array())
  30. {
  31. $this->lang = $lang;
  32. $this->deleteAutoInfo();
  33. if(isset($_POST['registerinfo_upload'])){
  34. $this->saveRgisterInfo();
  35. $this->getstatus();
  36. }
  37. }
  38. function deleteAutoInfo(){
  39. require_once BASE_CLASS . 'class-connect.php';
  40. $cnx = new Connect();
  41. $cnx->open();
  42. if(isset($_GET['delete'])) $delete=mysql_real_escape_string(stripslashes($_GET['delete'])); else $delete='';
  43. $owner = (int)$_SESSION['log_id'];
  44. if(!empty($delete)){
  45. if($this->foundAutoInfo($delete, $owner)){
  46. $sql_delete="DELETE from `auto_info` WHERE `id` = '$delete' AND `owner`='$owner'";
  47. @mysql_query($sql_delete);
  48. header("Location: auto-info?deleteresult=success");
  49. }else{
  50. header("Location: show-autoinfo?id={$delete}&deleteresult=fail");
  51. }
  52. }
  53. }
  54. function foundAutoInfo($id, $owner){
  55. require_once BASE_CLASS . 'class-connect.php';
  56. $cnx = new Connect();
  57. $cnx->open();
  58. $sql_search="SELECT * from auto_info WHERE id = '$id' AND `owner`='$owner'";
  59. $sql= @mysql_query($sql_search) ;
  60. if(mysql_num_rows($sql)>0) return true;
  61. @mysql_free_result($sql);
  62. $cnx->close();
  63. return $deal_week;
  64. }
  65. function loadAutoInfo($get_id){
  66. require_once BASE_CLASS . 'class-connect.php';
  67. $cnx = new Connect();
  68. $cnx->open();
  69. $sql_search="SELECT * from auto_info WHERE id = '$get_id'";
  70. if( !$sql = @mysql_query($sql_search) ){
  71. require_once BASE_CLASS . 'class-log.php';
  72. LogReport::write('Unable to load car maker list due a query error at ' . __FILE__ . ':' . __LINE__);
  73. $cnx->close();
  74. return;
  75. }
  76. if( @mysql_num_rows($sql) < 1 ){
  77. $cnx->close();
  78. }
  79. $deal_week = mysql_fetch_array($sql);
  80. @mysql_free_result($sql);
  81. $cnx->close();
  82. return $deal_week;
  83. }
  84. private function uploadfile(){
  85. $allowedExts = array("gif", "jpeg", "jpg", "png");
  86. $temp = explode(".", $_FILES["myfile"]["name"]);
  87. $extension = end($temp);
  88. if ((($_FILES["myfile"]["type"] == "image/gif")
  89. || ($_FILES["myfile"]["type"] == "image/jpeg")
  90. || ($_FILES["myfile"]["type"] == "image/jpg")
  91. || ($_FILES["myfile"]["type"] == "image/pjpeg")
  92. || ($_FILES["myfile"]["type"] == "image/x-png")
  93. || ($_FILES["myfile"]["type"] == "image/png"))
  94. && ($_FILES["myfile"]["size"] < 20480000)
  95. && in_array($extension, $allowedExts))
  96. {
  97. if ($_FILES["myfile"]["error"] > 0)
  98. {
  99. $this->form_message = $_FILES["myfile"]["error"];
  100. $this->form_status = true;
  101. $this->form_style = 'alert-error';
  102. $this->status="upload";
  103. //echo "Return Code: " . $_FILES["myfile"]["error"] . "<br>";
  104. }
  105. else
  106. {
  107. LogReport::write('File Upload Successfully ' . $_FILES["myfile"]["name"] . ':' . $_FILES["myfile"]["type"]. '. ' . ($_FILES["myfile"]["size"] / 1024).'kB' );
  108. //echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  109. // echo "Type: " . $_FILES["file"]["type"] . "<br>";
  110. // echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  111. // echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
  112. if (file_exists("image/deal_week/" . $_FILES["myfile"]["name"]))
  113. {
  114. LogReport::write('This file is already exists' . $_FILES["myfile"]["name"] . ':' . $_FILES["myfile"]["type"]. '. ' . ($_FILES["myfile"]["size"] / 1024).'kB' );
  115. $dtime = new DateTime();
  116. $dtime->format('YYYY-mmm-dd H:i:s');
  117. $timestamp = $dtime->getTimestamp();
  118. $filename = $timestamp.".". $extension;
  119. move_uploaded_file($_FILES["myfile"]["tmp_name"],
  120. "image/auto_info/" . $filename);
  121. //$main_image=new resize("image/auto_info/" . $filename);
  122. //$main_image->resizeImage(210, 155, 'crop');
  123. //$main_image->saveImage("image/auto_info/" . $filename, 100);
  124. $this->url="image/auto_info/".$filename;
  125. }
  126. else
  127. {
  128. $dtime = new DateTime();
  129. $dtime->format('YYYY-mmm-dd H:i:s');
  130. $timestamp = $dtime->getTimestamp();
  131. $filename = $timestamp.".". $extension;
  132. move_uploaded_file($_FILES["myfile"]["tmp_name"],
  133. "image/auto_info/" . $filename);
  134. //$main_image=new resize("image/auto_info/" . $filename);
  135. //$main_image->resizeImage(210, 155, 'crop');
  136. //$main_image->saveImage("image/auto_info/" . $filename, 100);
  137. $this->url="image/auto_info/".$filename;
  138. //echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  139. }
  140. }
  141. }
  142. else
  143. {
  144. LogReport::write('This file is Invalid file' . $_FILES["myfile"]["name"] . ':' . $_FILES["myfile"]["type"]. '.' .($_FILES["myfile"]["size"] / 1024).'kB' );
  145. $this->form_message = 'This file is Invalid file.';
  146. $this->form_status = true;
  147. $this->form_style = 'alert-error';
  148. $this->status="upload";
  149. return;
  150. }
  151. }
  152. function loadProduct(){
  153. require_once BASE_CLASS . 'class-connect.php';
  154. $cnx = new Connect();
  155. $cnx->open();
  156. $sql_search="SELECT DISTINCT make from product WHERE make <>'' ";
  157. if( !$sql = @mysql_query($sql_search) ){
  158. require_once BASE_CLASS . 'class-log.php';
  159. LogReport::write('Unable to load car maker list due a query error at ' . __FILE__ . ':' . __LINE__);
  160. $cnx->close();
  161. return;
  162. }
  163. if( @mysql_num_rows($sql) < 1 ){
  164. $cnx->close();
  165. }
  166. $auto_info = array();
  167. while( $r = @mysql_fetch_assoc($sql)){
  168. array_push($auto_info, $r);
  169. }
  170. @mysql_free_result($sql);
  171. $cnx->close();
  172. return $auto_info;
  173. }
  174. public function saveRgisterInfo(){
  175. require_once BASE_CLASS . 'class-connect.php';
  176. $category = $_POST['radio'];
  177. $item = $_POST['item'];
  178. $maker = $_POST['maker'];
  179. $model = $_POST['model'];
  180. $topic = $_POST['topic'];
  181. $message = $_POST['htmlInput'];
  182. $this->uploadfile();
  183. $image_name=$this->url;
  184. $cnx = new Connect();
  185. $cnx->open();
  186. if($category=='' || $item=='Select' || $maker=='Select' || $model=='' || $topic=="" || $message==""){
  187. $this->status ='error';
  188. }
  189. else{
  190. $sql_insert="INSERT INTO auto_info (category, item, make, model, topic, writen_by, `date`, message, image )
  191. VALUES ('$category', '$item', '$maker', '$model', '$topic', '{$_SESSION['log_name']}', NOW(), '$message', '$image_name')";
  192. $this->status = 'ok';
  193. //echo $sql_insert;
  194. if( !$sql = @mysql_query($sql_insert) ){
  195. require_once BASE_CLASS . 'class-log.php';
  196. LogReport::write('Unable to load car maker list due a query error at ' . __FILE__ . ':' . __LINE__);
  197. $this->status = 'ok';
  198. $cnx->close();
  199. return;
  200. }
  201. }
  202. @mysql_free_result($sql);
  203. $cnx->close();
  204. }
  205. /*
  206. * Public method: get page content data ------------------------------------
  207. * @return array | false.
  208. */
  209. public function getPageHTML()
  210. {
  211. require_once BASE_ROOT . 'core/class-connect.php';
  212. $cnx = new Connect();
  213. $cnx->open();
  214. if( !$sql = @mysql_query("SELECT * FROM `page` WHERE `page_slug`='$this->slug' AND `page_group`='$this->group' LIMIT 1;") )
  215. {
  216. $cnx->close();
  217. require_once BASE_ROOT . 'core/class-log.php';
  218. LogReport::write('Unable to load page information at ' . __FILE__ . ':' . __LINE__ . '. ' . mysql_error());
  219. $this->form_message = 'Unable to load page content due an internal error.';
  220. $this->form_status = true;
  221. $this->form_style = 'alert-error';
  222. return;
  223. }
  224. if( @mysql_num_rows($sql) != 1 )
  225. {
  226. $cnx->close();
  227. require_once BASE_ROOT . 'core/class-log.php';
  228. LogReport::write('Unable to load page information at ' . __FILE__ . ':' . __LINE__ . '. ' . mysql_error());
  229. $this->form_message = 'Unable to load page content due an internal error.';
  230. $this->form_status = true;
  231. $this->form_style = 'alert-error';
  232. return;
  233. }
  234. $r = @mysql_fetch_assoc($sql);
  235. $result = array();
  236. $result['id'] = $r['id'];
  237. $result['meta_keywords'] = $r['meta_keywords'];
  238. $result['meta_description'] = $r['meta_description'];
  239. $result['meta_robots'] = $r['meta_robots'];
  240. $result['page_title'] = $r['page_title'];
  241. $result['page_slug'] = $r['page_slug'];
  242. $result['page_publish'] = $r['page_publish'];
  243. $result['page_author'] = $r['page_author'];
  244. $result['creation'] = $r['creation'];
  245. $result['editable'] = $r['editable'];
  246. $result['page_group'] = $r['page_group'];
  247. $result['html'] = $r['html'];
  248. @mysql_free_result($sql);
  249. $cnx->close();
  250. return $result;
  251. }
  252. /*
  253. * Public method: get form status ------------------------------------------
  254. * @return bool.
  255. */
  256. public function getFormStatus()
  257. {
  258. return $this->form_status;
  259. }
  260. /*
  261. * Public method: get form message -----------------------------------------
  262. * @return string.
  263. */
  264. public function getFormMessage()
  265. {
  266. return $this->form_message;
  267. }
  268. /*
  269. * Public method: get form style -------------------------------------------
  270. * @return string.
  271. */
  272. public function getFormStyle()
  273. {
  274. return $this->form_style;
  275. }
  276. public function getstatus()
  277. {
  278. return $this->status;
  279. }
  280. }
  281. ?>