PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/app/controllers/sitehelp_controller.php

https://bitbucket.org/fxrialab/tickets
PHP | 690 lines | 541 code | 106 blank | 43 comment | 55 complexity | d180ab9a88aa2067df4a1e0cbf232f90 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0, MIT
  1. <?php
  2. class SitehelpController extends AppController
  3. {
  4. var $name='Sitehelp';
  5. var $components = array('Pagination','Upload');
  6. var $helpers = array('Pagination', 'error');
  7. function index()
  8. {
  9. $this->checkSession();
  10. $this->layout = 'default_user_cat';
  11. if($_SESSION['Admin_role']==1)
  12. {
  13. $criteria= "1";
  14. ///list($order,$limit,$page) = $this->Pagination->init($criteria);
  15. $this->set('sitehelps', $this->Sitehelp->findAll());
  16. }
  17. else
  18. $this->redirect('/sitehelp/index');
  19. }
  20. function edit_head($id=null)
  21. {
  22. $this->checkSession();
  23. $this->layout = 'default_user_cat';
  24. /* For data related to categry */
  25. if($id)
  26. {
  27. $catsql = "Select * from sitehelps where id='".$id."'";
  28. $catsql_res = mysql_query($catsql);
  29. $catsql_arr = mysql_fetch_array($catsql_res);
  30. $this->set('sitehelpcategory', $catsql_arr);
  31. }
  32. else
  33. $this->redirect('/sitehelp/index');
  34. }
  35. function saveedithead()
  36. {
  37. $this->checkSession();
  38. $this->layout = 'default_user_cat';
  39. /* For data related to categry */
  40. if(isset($_REQUEST['helpcatid']) && $_REQUEST['helpcatid']>0)
  41. {
  42. $catedit = "UPDATE sitehelps SET cat_name = '".$this->data['sitehelp']['cat_name']."',cat_desc='".strip_html_tags($this->data['sitehelp']['cat_desc'])."' where id='".$_REQUEST['helpcatid']."'";
  43. mysql_query($catedit);
  44. }
  45. $this->redirect('/sitehelp/index');
  46. }
  47. function addhelpcategory()
  48. {
  49. $this->checkSession();
  50. $this->layout = 'default_user_cat';
  51. }
  52. function saveheadcategory()
  53. {
  54. $this->checkSession();
  55. $this->layout = 'default_user_cat';
  56. /* For data related to categry */
  57. $catsql = "Select * from sitehelps where cat_name = '".$this->data['sitehelp']['cat_name']."'";
  58. $catsql_res = mysql_query($catsql);
  59. if(mysql_num_rows($catsql_res)==0)
  60. {
  61. $catedit = "INSERT INTO sitehelps SET cat_name = '".$this->data['sitehelp']['cat_name']."',cat_desc='".strip_html_tags($this->data['sitehelp']['cat_desc'])."'";
  62. mysql_query($catedit);
  63. }
  64. $this->redirect('/sitehelp/index');
  65. }
  66. function delete_head($id=null)
  67. {
  68. $this->checkSession();
  69. $this->layout = 'default_user_cat';
  70. if($id)
  71. {
  72. $catedit = "DELETE FROM sitehelps where id='".$id."'";
  73. mysql_query($catedit);
  74. }
  75. $this->redirect('/sitehelp/index');
  76. }
  77. function managecategoryhead()
  78. {
  79. if(isset($_REQUEST['box']))
  80. {
  81. $boxarray = $_REQUEST['box'] ;
  82. foreach($boxarray as $boxarrayind=>$boxarrayval)
  83. {
  84. $catedit = "DELETE FROM sitehelps where id='".$boxarrayval."'";
  85. mysql_query($catedit);
  86. }
  87. }
  88. $this->redirect('/sitehelp/index');
  89. }
  90. function view_group_head($id=null)
  91. {
  92. $this->checkSession();
  93. $this->layout = 'default_user_cat';
  94. if($id)
  95. {
  96. $this->set('groupName', $this->Sitehelp->findById($id));
  97. /* Group sql */
  98. $groupsql = "
  99. SELECT sitehelp_group.id, sitehelp_group.group_name, COUNT(sitehelp_group_topic.id) as Numberoftopic , COUNT(sitehelp_group_topic_qa.id) as Numberofquestion
  100. from sitehelp_group
  101. LEFT JOIN sitehelp_group_topic ON sitehelp_group.id=sitehelp_group_topic.sitehelp_group_id
  102. LEFT JOIN sitehelp_group_topic_qa ON sitehelp_group_topic.id=sitehelp_group_topic_qa.sitehelp_group_topic_id
  103. WHERE sitehelp_group.sitehelp_id = '".$id."' Group by sitehelp_group.id ";
  104. $this->set('groupquery', $groupsql);
  105. }
  106. else
  107. $this->redirect('/sitehelp/index');
  108. }
  109. function addhelpgrouphead($id=null)
  110. {
  111. $this->checkSession();
  112. $this->layout = 'default_user_cat';
  113. $this->set('groupName', $this->Sitehelp->findById($id));
  114. }
  115. function savegroupheadcategory()
  116. {
  117. $this->checkSession();
  118. $this->layout = 'default_user_cat';
  119. /* For data related to categry */
  120. $catsql = "Select * from sitehelp_group where group_name = '".$this->data['sitehelpGroup']['group_name']."' and sitehelp_id='".$_REQUEST['helpgroupid']."'";
  121. $catsql_res = mysql_query($catsql);
  122. if(mysql_num_rows($catsql_res)==0)
  123. {
  124. $catedit = "INSERT INTO sitehelp_group SET group_name = '".$this->data['sitehelpGroup']['group_name']."',sitehelp_id='".$_REQUEST['helpgroupid']."'";
  125. mysql_query($catedit);
  126. }
  127. $this->redirect('/sitehelp/view_group_head/'.$_REQUEST['helpgroupid']);
  128. }
  129. function edit_group_head($id=null)
  130. {
  131. $this->checkSession();
  132. $this->layout = 'default_user_cat';
  133. if($id)
  134. {
  135. $catsql = "Select * from sitehelp_group where id='".$id."'";
  136. $catsql_res = mysql_query($catsql);
  137. $catsql_arr = mysql_fetch_array($catsql_res);
  138. $this->set('sitehelpgroupcategory', $catsql_arr);
  139. }
  140. else
  141. $this->redirect('/sitehelp/index');
  142. }
  143. function saveeditgrouphead()
  144. {
  145. $this->checkSession();
  146. $this->layout = 'default_user_cat';
  147. if(isset($_REQUEST['helpgroupheadid']) && $_REQUEST['helpgroupheadid']>0)
  148. {
  149. $catedit = "UPDATE sitehelp_group SET group_name = '".$this->data['sitehelpGroup']['group_name']."' where id='".$_REQUEST['helpgroupheadid']."'";
  150. mysql_query($catedit);
  151. $this->redirect('/sitehelp/view_group_head/'.$_REQUEST['helpgroupheadid']);
  152. }
  153. else
  154. $this->redirect('/sitehelp/index');
  155. }
  156. function delete_group_head($id=null)
  157. {
  158. if($id)
  159. {
  160. $catedit = "DELETE FROM sitehelp_group where id='".$id."'";
  161. mysql_query($catedit);
  162. $this->redirect($_SERVER['HTTP_REFERER']);
  163. }
  164. else
  165. $this->redirect('/sitehelp/index');
  166. }
  167. function view_group_topic($groupid=null)
  168. {
  169. $this->checkSession();
  170. $this->layout = 'default_user_cat';
  171. if($groupid)
  172. {
  173. $groupsql = "
  174. SELECT sitehelps.cat_name as CatName , sitehelps.id as CatId , sitehelp_group.id as groupid, sitehelp_group.group_name, sitehelp_group_topic.topic , sitehelp_group_topic.id ,COUNT(sitehelp_group_topic_qa.id) as Numberofquestion
  175. from sitehelp_group_topic
  176. LEFT JOIN sitehelp_group ON sitehelp_group_topic.sitehelp_group_id=sitehelp_group.id
  177. LEFT JOIN sitehelps ON sitehelp_group.sitehelp_id=sitehelps.id
  178. LEFT JOIN sitehelp_group_topic_qa ON sitehelp_group_topic.id=sitehelp_group_topic_qa.sitehelp_group_topic_id
  179. WHERE sitehelp_group_topic.sitehelp_group_id = '".$groupid."' Group by sitehelp_group_topic.id ";
  180. $this->set('groupquery', $groupsql);
  181. /** GROUP NAME AND CATEGORY NAME */
  182. $groupcatsql = "Select sitehelps.cat_name,sitehelps.id as helpcatid , sitehelp_group.* from sitehelp_group
  183. LEFT JOIN sitehelps ON sitehelp_group.sitehelp_id = sitehelps.id
  184. where sitehelp_group.id='".$groupid."'";
  185. $groupcatsql_res = mysql_query($groupcatsql);
  186. $groupcatsql_arr = mysql_fetch_array($groupcatsql_res);
  187. $this->set('groupcatsql', $groupcatsql_arr);
  188. /***/
  189. }
  190. else
  191. $this->redirect('/sitehelp/index');
  192. }
  193. function addquestiontopic($groupid=null)
  194. {
  195. $this->checkSession();
  196. $this->layout = 'default_user_cat';
  197. /** GROUP NAME AND CATEGORY NAME */
  198. $groupcatsql = "Select sitehelps.cat_name,sitehelps.id as helpcatid , sitehelp_group.* from sitehelp_group
  199. LEFT JOIN sitehelps ON sitehelp_group.sitehelp_id = sitehelps.id
  200. where sitehelp_group.id='".$groupid."'";
  201. $groupcatsql_res = mysql_query($groupcatsql);
  202. $groupcatsql_arr = mysql_fetch_array($groupcatsql_res);
  203. $this->set('groupcatsql', $groupcatsql_arr);
  204. /***/
  205. }
  206. function savequestiontopic()
  207. {
  208. $this->checkSession();
  209. $this->layout = 'default_user_cat';
  210. if(isset($_REQUEST['helpgroupid']) && $_REQUEST['helpgroupid']>0)
  211. {
  212. $inserttopic = "INSERT INTO sitehelp_group_topic SET sitehelp_id='".$_REQUEST['helpcatid']."' ,sitehelp_group_id='".$_REQUEST['helpgroupid']."' , topic='".$this->data['sitehelpGroupTopic']['topic']."' ";
  213. mysql_query($inserttopic);
  214. }
  215. $this->redirect('/sitehelp/view_group_topic/'.$_REQUEST['helpgroupid']);
  216. }
  217. function edit_group_topic($topicid=null)
  218. {
  219. $this->checkSession();
  220. $this->layout = 'default_user_cat';
  221. /** GROUP NAME AND CATEGORY NAME */
  222. $topicsql = " SELECT sitehelps.cat_name,sitehelps.id as helpcatid , sitehelp_group.id as helpgroupid , sitehelp_group.group_name, sitehelp_group_topic.* from sitehelp_group_topic
  223. LEFT JOIN sitehelp_group ON sitehelp_group_topic.sitehelp_group_id =sitehelp_group.id
  224. LEFT JOIN sitehelps ON sitehelp_group_topic.sitehelp_id=sitehelps.id
  225. where sitehelp_group_topic.id='".$topicid."'" ;
  226. $groupcatsql_res = mysql_query($topicsql);
  227. $groupcatsql_arr = mysql_fetch_array($groupcatsql_res);
  228. $this->set('groupcatsql', $groupcatsql_arr);
  229. }
  230. function saveeditquestiontopic()
  231. {
  232. //pr($_REQUEST);
  233. $this->checkSession();
  234. $this->layout = 'default_user_cat';
  235. if(isset($_REQUEST['helptopicid']) && $_REQUEST['helptopicid']>0)
  236. {
  237. $updatesql= "UPDATE sitehelp_group_topic SET topic='".$this->data['sitehelpGroupTopic']['topic']."' Where id = '".$_REQUEST['helptopicid']."'";
  238. mysql_query($updatesql);
  239. $topicsql = " SELECT sitehelp_group.id as helpgroupid from sitehelp_group_topic
  240. LEFT JOIN sitehelp_group ON sitehelp_group_topic.sitehelp_group_id =sitehelp_group.id
  241. LEFT JOIN sitehelps ON sitehelp_group_topic.sitehelp_id=sitehelps.id
  242. where sitehelp_group_topic.id='".$_REQUEST['helptopicid']."'" ;
  243. $groupcatsql_res = mysql_query($topicsql);
  244. $groupcatsql_arr = mysql_fetch_array($groupcatsql_res);
  245. $this->redirect('/sitehelp/view_group_topic/'.$groupcatsql_arr['helpgroupid']);
  246. }
  247. else
  248. $this->redirect('/sitehelp/index');
  249. }
  250. function delete_group_topic($topicid=null)
  251. {
  252. $this->checkSession();
  253. $this->layout = 'default_user_cat';
  254. if($topicid)
  255. {
  256. $topicsql = " SELECT sitehelp_group.id as helpgroupid from sitehelp_group_topic
  257. LEFT JOIN sitehelp_group ON sitehelp_group_topic.sitehelp_group_id =sitehelp_group.id
  258. LEFT JOIN sitehelps ON sitehelp_group_topic.sitehelp_id=sitehelps.id
  259. where sitehelp_group_topic.id='".$topicid."'" ;
  260. $groupcatsql_res = mysql_query($topicsql);
  261. $groupcatsql_arr = mysql_fetch_array($groupcatsql_res);
  262. $updatesql= "DELETE FROM sitehelp_group_topic Where id = '".$topicid."'";
  263. mysql_query($updatesql);
  264. $this->redirect('/sitehelp/view_group_topic/'.$groupcatsql_arr['helpgroupid']);
  265. }
  266. else
  267. $this->redirect('/sitehelp/index');
  268. }
  269. function view_group_topic_question($topicid=null)
  270. {
  271. if($topicid)
  272. {
  273. $this->checkSession();
  274. $this->layout = 'default_user_cat';
  275. $grouptopicsql = "
  276. SELECT sitehelps.cat_name as CatName , sitehelps.id as CatId , sitehelp_group.id as groupid, sitehelp_group.group_name, sitehelp_group_topic.topic
  277. , sitehelp_group_topic.id ,sitehelp_group_topic_qa.*
  278. from sitehelp_group_topic_qa
  279. LEFT JOIN sitehelp_group_topic ON sitehelp_group_topic_qa.sitehelp_group_topic_id = sitehelp_group_topic.id
  280. LEFT JOIN sitehelp_group ON sitehelp_group_topic.sitehelp_group_id=sitehelp_group.id
  281. LEFT JOIN sitehelps ON sitehelp_group.sitehelp_id=sitehelps.id
  282. WHERE sitehelp_group_topic_qa.sitehelp_group_topic_id = '".$topicid."' ";
  283. $this->set('grouptopicquery', $grouptopicsql);
  284. /** GROUP NAME AND CATEGORY NAME */
  285. /*$groupcatsql = "Select sitehelps.cat_name,sitehelps.id as helpcatid , sitehelp_group.* from sitehelp_group
  286. LEFT JOIN sitehelps ON sitehelp_group.sitehelp_id = sitehelps.id
  287. where sitehelp_group.id='".$groupid."'";*/
  288. $groupcatsql = "
  289. SELECT sitehelps.cat_name as CatName , sitehelps.id as CatId , sitehelp_group.id as groupid, sitehelp_group.group_name, sitehelp_group_topic.topic
  290. , sitehelp_group_topic.id
  291. from sitehelp_group_topic
  292. LEFT JOIN sitehelp_group ON sitehelp_group_topic.sitehelp_group_id=sitehelp_group.id
  293. LEFT JOIN sitehelps ON sitehelp_group.sitehelp_id=sitehelps.id
  294. LEFT JOIN sitehelp_group_topic_qa ON sitehelp_group_topic.id=sitehelp_group_topic_qa.sitehelp_group_topic_id
  295. WHERE sitehelp_group_topic.id = '".$topicid."' ";
  296. $groupcatsql_res = mysql_query($groupcatsql);
  297. $groupcatsql_arr = mysql_fetch_array($groupcatsql_res);
  298. $this->set('groupcatsql', $groupcatsql_arr);
  299. /***/
  300. }
  301. else
  302. $this->redirect('/sitehelp/index');
  303. }
  304. function addquestion($categoryId=null , $groupId=null,$grouptopicId=null)
  305. {
  306. $this->checkSession();
  307. $this->layout = 'default_user_cat';
  308. $this->set('catgoryId',$categoryId);
  309. $this->set('groupId',$groupId);
  310. $this->set('grouptopicId',$grouptopicId);
  311. $categoryarr = array();
  312. /* Category array */
  313. $categorysql = "SELECT * from sitehelps where 1 ";
  314. if($categoryId)
  315. $categorysql .= " AND id='".$categoryId."'";
  316. $categorysql_res = mysql_query($categorysql);
  317. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  318. {
  319. $categoryarr[$categorysql_arr['id']] = $categorysql_arr['cat_name'] ;
  320. }
  321. $this->set('categoryList',$categoryarr );
  322. /**/
  323. /*Group list*/
  324. $grouparr = array();
  325. $categorysql = "SELECT * from sitehelp_group where 1 ";
  326. if($categoryId)
  327. $categorysql .= " AND sitehelp_id='".$categoryId."'";
  328. if($groupId)
  329. $categorysql .= " AND id ='".$groupId."'";
  330. $categorysql_res = mysql_query($categorysql);
  331. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  332. {
  333. $grouparr[$categorysql_arr['id']] = $categorysql_arr['group_name'] ;
  334. }
  335. $this->set('groupList',$grouparr );
  336. /**/
  337. /* TOPIC ARRAY */
  338. $topiicarr = array();
  339. $topicsql = "Select * from sitehelp_group_topic WHERE 1 ";
  340. if($categoryId)
  341. $topicsql .= " AND sitehelp_id='".$categoryId."'";
  342. if($groupId)
  343. $topicsql .= " AND sitehelp_group_id='".$groupId."'";
  344. if($grouptopicId)
  345. $topicsql .= " AND id='".$grouptopicId."'";
  346. $categorysql_res = mysql_query($topicsql);
  347. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  348. {
  349. $topiicarr[$categorysql_arr['id']] = $categorysql_arr['topic'] ;
  350. }
  351. $this->set('topicList',$topiicarr );
  352. /**/
  353. }
  354. function edit_group_topic_question_answer($questionId=null)
  355. {
  356. $this->checkSession();
  357. $this->layout = 'default_user_cat';
  358. ########################################### QUESTION INFORMATION
  359. $questionsql = "SELECT * from sitehelp_group_topic_qa where id='".$questionId."'";
  360. $questionsql_res = mysql_query($questionsql);
  361. $questionsql_arr = mysql_fetch_array($questionsql_res);
  362. $categoryId = $questionsql_arr['sitehelp_id'];
  363. $groupId = $questionsql_arr['sitehelp_group_id'];
  364. $grouptopicId = $questionsql_arr['sitehelp_group_topic_id'];
  365. $groupquestion = $questionsql_arr['question'];
  366. $groupanswwer = $questionsql_arr['answer'];
  367. $screenshotImage = $questionsql_arr['screenshot'];
  368. $sitequestionId = $questionId;
  369. $this->set('catgoryId',$categoryId);
  370. $this->set('groupId',$groupId);
  371. $this->set('grouptopicId',$grouptopicId);
  372. $this->set('question',$groupquestion);
  373. $this->set('answer',$groupanswwer);
  374. $this->set('screenshotImage',$screenshotImage);
  375. $this->set('sitequestionId',$sitequestionId);
  376. $categoryarr = array();
  377. /* Category array */
  378. $categorysql = "SELECT * from sitehelps where 1 ";
  379. if($categoryId)
  380. $categorysql .= " AND id='".$categoryId."'";
  381. $categorysql_res = mysql_query($categorysql);
  382. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  383. {
  384. $categoryarr[$categorysql_arr['id']] = $categorysql_arr['cat_name'] ;
  385. }
  386. $this->set('categoryList',$categoryarr );
  387. /**/
  388. /*Group list*/
  389. $grouparr = array();
  390. $categorysql = "SELECT * from sitehelp_group where 1 ";
  391. if($categoryId)
  392. $categorysql .= " AND sitehelp_id='".$categoryId."'";
  393. if($groupId)
  394. $categorysql .= " AND id ='".$groupId."'";
  395. $categorysql_res = mysql_query($categorysql);
  396. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  397. {
  398. $grouparr[$categorysql_arr['id']] = $categorysql_arr['group_name'] ;
  399. }
  400. $this->set('groupList',$grouparr );
  401. /**/
  402. /* TOPIC ARRAY */
  403. $topiicarr = array();
  404. $topicsql = "Select * from sitehelp_group_topic WHERE 1 ";
  405. if($categoryId)
  406. $topicsql .= " AND sitehelp_id='".$categoryId."'";
  407. if($groupId)
  408. $topicsql .= " AND sitehelp_group_id='".$groupId."'";
  409. if($grouptopicId)
  410. $topicsql .= " AND id='".$grouptopicId."'";
  411. $categorysql_res = mysql_query($topicsql);
  412. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  413. {
  414. $topiicarr[$categorysql_arr['id']] = $categorysql_arr['topic'] ;
  415. }
  416. $this->set('topicList',$topiicarr );
  417. /**/
  418. }
  419. function savequestion($questionid=null)
  420. {
  421. $destination = realpath('../../../app/webroot/sitehelpscreen/') . '/';
  422. $file = $this->data['sitehelpGroupTopicQa']['screenshot'];
  423. $Uploadfile = '';
  424. // upload the image using the upload component
  425. if($file!='')
  426. $result = $this->Upload->upload($file, $destination, null, array('type' => 'resizecrop', 'size' => array('400', '300'), 'output' => 'jpg'));
  427. if($result!='')
  428. $Uploadfile = basename($result);
  429. /* INSERTINO in the sitehelp_group_topic_qa Table */
  430. if($questionid)
  431. {
  432. $insertssql = "UPDATE sitehelp_group_topic_qa SET sitehelp_id = '".$this->data['sitehelpGroupTopicQa']['sitehelp_id']."' , sitehelp_group_id = '".$this->data['sitehelpGroupTopicQa']['sitehelp_group_id']."' ,
  433. sitehelp_group_topic_id='".$this->data['sitehelpGroupTopicQa']['sitehelp_group_topic_id']."' , question ='".addslashes($this->data['sitehelpGroupTopicQa']['question'])."' , answer = '".addslashes($this->data['sitehelpGroupTopicQa']['answer'])."' " ;
  434. if($Uploadfile!='')
  435. $insertssql .= " , screenshot ='".$Uploadfile."' " ;
  436. $insertssql .= " where id='".$questionid."' " ;
  437. }
  438. else
  439. {
  440. $insertssql = "INSERT INTO sitehelp_group_topic_qa SET sitehelp_id = '".$this->data['sitehelpGroupTopicQa']['sitehelp_id']."' , sitehelp_group_id = '".$this->data['sitehelpGroupTopicQa']['sitehelp_group_id']."' ,
  441. sitehelp_group_topic_id='".$this->data['sitehelpGroupTopicQa']['sitehelp_group_topic_id']."' , question ='".addslashes($this->data['sitehelpGroupTopicQa']['question'])."' , answer = '".addslashes($this->data['sitehelpGroupTopicQa']['answer'])."' , screenshot ='".$Uploadfile."' " ;
  442. }
  443. $insertssql_sql = mysql_query($insertssql);
  444. //echo $insertssql ;
  445. $this->redirect('/sitehelp/groupquestionlist/'.$this->data['sitehelpGroupTopicQa']['sitehelp_id'] .'/'. $this->data['sitehelpGroupTopicQa']['sitehelp_group_id'].'/'.$this->data['sitehelpGroupTopicQa']['sitehelp_group_topic_id']);
  446. }
  447. function groupquestionlist($sitehelpId=null,$groupId=null,$groupTopicId=null)
  448. {
  449. $this->checkSession();
  450. $this->layout = 'default_user_cat';
  451. $Questionlist = "
  452. Select sitehelps.cat_name As categoryName, sitehelp_group.group_name As groupName ,sitehelp_group_topic.topic As topicName , sitehelp_group_topic_qa.* from sitehelp_group_topic_qa
  453. LEFT JOIN sitehelps ON sitehelp_group_topic_qa.sitehelp_id = sitehelps.id
  454. LEFT JOIN sitehelp_group ON sitehelp_group_topic_qa.sitehelp_group_id = sitehelp_group.id
  455. LEFT JOIN sitehelp_group_topic ON sitehelp_group_topic_qa.sitehelp_group_topic_id = sitehelp_group_topic.id
  456. where 1 ";
  457. if($sitehelpId)
  458. {
  459. $Questionlist .= " AND sitehelp_group_topic_qa.sitehelp_id = '". $sitehelpId ."' " ;
  460. $this->set('groupCatId' ,$sitehelpId );
  461. }
  462. if($groupId)
  463. {
  464. $Questionlist .= " AND sitehelp_group_topic_qa.sitehelp_group_id = '". $groupId ."' " ;
  465. }
  466. if($groupTopicId)
  467. {
  468. $Questionlist .= " AND sitehelp_group_topic_qa.sitehelp_group_topic_id = '". $groupTopicId ."' " ;
  469. }
  470. $this->set('questionsql',$Questionlist);
  471. }
  472. function edit_question($questionid=null)
  473. {
  474. $this->checkSession();
  475. $this->layout = 'default_user_cat';
  476. $categoryarr = array();
  477. /* Category array */
  478. $categorysql = "SELECT * from sitehelps where 1 ";
  479. $categorysql_res = mysql_query($categorysql);
  480. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  481. {
  482. $categoryarr[$categorysql_arr['id']] = $categorysql_arr['cat_name'] ;
  483. }
  484. $this->set('categoryList',$categoryarr );
  485. /**/
  486. /*Group list*/
  487. $grouparr = array();
  488. $categorysql = "SELECT * from sitehelp_group where 1 ";
  489. $categorysql_res = mysql_query($categorysql);
  490. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  491. {
  492. $grouparr[$categorysql_arr['id']] = $categorysql_arr['group_name'] ;
  493. }
  494. $this->set('groupList',$grouparr );
  495. /**/
  496. /* TOPIC ARRAY */
  497. $topiicarr = array();
  498. $topicsql = "Select * from sitehelp_group_topic WHERE 1 ";
  499. $categorysql_res = mysql_query($topicsql);
  500. while($categorysql_arr = mysql_fetch_array($categorysql_res))
  501. {
  502. $topiicarr[$categorysql_arr['id']] = $categorysql_arr['topic'] ;
  503. }
  504. $this->set('topicList',$topiicarr );
  505. /* QUESTION LIST */
  506. if($questionid)
  507. {
  508. $Questionlist = "Select sitehelp_group_topic_qa.* from sitehelp_group_topic_qa
  509. where sitehelp_group_topic_qa.id='".$questionid."' ";
  510. $Questionlist_res = mysql_query($Questionlist);
  511. $Questionlist_arr = mysql_fetch_array($Questionlist_res);
  512. $this->set('helpcatId' , $Questionlist_arr['sitehelp_id']);
  513. $this->set('helpgroupId' , $Questionlist_arr['sitehelp_group_id']);
  514. $this->set('helpgrouptopicId' , $Questionlist_arr['sitehelp_group_topic_id']);
  515. $this->set('helpquestion' , $Questionlist_arr['question']);
  516. $this->set('helpanswer' , $Questionlist_arr['answer']);
  517. $this->set('helpscreen' , $Questionlist_arr['screenshot']);
  518. $this->set('helpId' , $Questionlist_arr['id']);
  519. $this->set('helpaction' , 'edit');
  520. }
  521. else
  522. $this->set('helpaction' , 'insert');
  523. /**/
  524. }
  525. function saveeditquestion()
  526. {
  527. $destination = realpath('../../../app/webroot/sitehelpscreen/') . '/';
  528. $file = $this->data['sitehelpGroupTopicQa']['screenshot'];
  529. $Uploadfile = '';
  530. // upload the image using the upload component
  531. $result = $this->Upload->upload($file, $destination, null, array('type' => 'resizecrop', 'size' => array('400', '300'), 'output' => 'jpg'));
  532. if($result!='')
  533. $Uploadfile = basename($result);
  534. /* INSERTINO in the sitehelp_group_topic_qa Table */
  535. if(isset($_REQUEST['questionaction']) && $_REQUEST['questionaction']=='insert')
  536. {
  537. $insertssql = "INSERT INTO sitehelp_group_topic_qa SET sitehelp_id = '".$this->data['sitehelpGroupTopicQa']['sitehelp_id']."' , sitehelp_group_id = '".$this->data['sitehelpGroupTopicQa']['sitehelp_group_id']."' ,
  538. sitehelp_group_topic_id='".$this->data['sitehelpGroupTopicQa']['sitehelp_group_topic_id']."' , question ='".$this->data['sitehelpGroupTopicQa']['question']."' , answer = '".addslashes($this->data['sitehelpGroupTopicQa']['answer'])."' , screenshot ='".$Uploadfile."' " ;
  539. $insertssql_sql = mysql_query($insertssql);
  540. }
  541. else
  542. {
  543. if(isset($_REQUEST['questionaction']) && $_REQUEST['questionaction']=='edit')
  544. {
  545. $updatequestion = "UPDATE sitehelp_group_topic_qa SET sitehelp_id = '".$this->data['sitehelpGroupTopicQa']['sitehelp_id']."' , sitehelp_group_id = '".$this->data['sitehelpGroupTopicQa']['sitehelp_group_id']."' ,
  546. sitehelp_group_topic_id='".$this->data['sitehelpGroupTopicQa']['sitehelp_group_topic_id']."' , question ='".$this->data['sitehelpGroupTopicQa']['question']."' , answer = '".addslashes($this->data['sitehelpGroupTopicQa']['answer'])."' ";
  547. if($Uploadfile!='')
  548. $updatequestion .= " , screenshot ='".$Uploadfile."' ";
  549. $updatequestion .= " where id='".$_REQUEST['questionid']."' ";
  550. $insertssql_sql = mysql_query($updatequestion);
  551. }
  552. }
  553. $this->redirect('/sitehelp/groupquestionlist/'.$this->data['sitehelpGroupTopicQa']['sitehelp_id'] .'/'. $this->data['sitehelpGroupTopicQa']['sitehelp_group_id'].'/'.$this->data['sitehelpGroupTopicQa']['sitehelp_group_topic_id']);
  554. }
  555. function view_question($questionid=null)
  556. {
  557. $this->checkSession();
  558. $this->layout = 'default_user_cat';
  559. /* QUESTION LIST */
  560. if($questionid)
  561. {
  562. $Questionlist = "
  563. Select sitehelps.cat_name As categoryName, sitehelp_group.group_name As groupName ,sitehelp_group_topic.topic As topicName , sitehelp_group_topic_qa.* from sitehelp_group_topic_qa
  564. LEFT JOIN sitehelps ON sitehelp_group_topic_qa.sitehelp_id = sitehelps.id
  565. LEFT JOIN sitehelp_group ON sitehelp_group_topic_qa.sitehelp_group_id = sitehelp_group.id
  566. LEFT JOIN sitehelp_group_topic ON sitehelp_group_topic_qa.sitehelp_group_topic_id = sitehelp_group_topic.id where sitehelp_group_topic_qa.id='".$questionid."' " ;
  567. $Questionlist_res = mysql_query($Questionlist);
  568. $Questionlist_arr = mysql_fetch_array($Questionlist_res);
  569. $this->set('helpcatName' , $Questionlist_arr['categoryName']);
  570. $this->set('helpgroupName' , $Questionlist_arr['groupName']);
  571. $this->set('helpgrouptopicName' , $Questionlist_arr['topicName']);
  572. $this->set('helpquestion' , $Questionlist_arr['question']);
  573. $this->set('helpanswer' , $Questionlist_arr['answer']);
  574. $this->set('helpscreen' , $Questionlist_arr['screenshot']);
  575. }
  576. }
  577. function delete_question($questionid=null)
  578. {
  579. $delsql = " DELETE from sitehelp_group_topic_qa where id='".$questionid."'" ;
  580. mysql_query($delsql);
  581. $this->redirect($_SERVER['HTTP_REFERER']);
  582. }
  583. }
  584. ?>