PageRenderTime 79ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/manager/application/controllers/moodlifter.php

https://bitbucket.org/jerwinse/iagh-cms
PHP | 1256 lines | 1101 code | 90 blank | 65 comment | 135 complexity | c8ec13e03c183ff52a4b4f1348315c9a MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Moodlifter extends CI_Controller{
  3. private $workspaceId;
  4. public function __construct(){
  5. parent::__construct();
  6. $this->tal->title = $this->config->item('title');
  7. $this->tal->base_url = substr(base_url(), 0, -1);
  8. $this->user = $this->ion_auth->user()->result();
  9. if(!$this->ion_auth->user()->result()){
  10. exit;
  11. }
  12. $this->user[0]->fullname = $this->user[0]->first_name . ' ' . $this->user[0]->last_name;
  13. $config = array('userID' => $this->user[0]->id);
  14. $this->load->library('acl', $config);
  15. $this->load->library('curl');
  16. $this->load->library('upload');
  17. $this->load->helper(array('form', 'url', 'file'));
  18. if (!$this->acl->userRoles) {
  19. exit;
  20. }
  21. else{
  22. $this->workspaceId = $this->acl->userRoles[0];
  23. }
  24. }
  25. public function papiCall($method="GET", $function="", $options=array()){
  26. $papi = array();
  27. $papi['method'] = $method;
  28. $papi['papiCall'] = $function;
  29. $papi['data'] = $options;
  30. $this->curl->PAPIConfig($papi);
  31. $res = $this->curl->execute();
  32. return json_decode($res['message']);
  33. }
  34. private function verifyMimeType($mimeType=""){
  35. $mimeType = strtolower($mimeType);
  36. $res = array();
  37. $valid = 0;
  38. $typeId = 0;
  39. # Types (1=Txt, 2=Image, 3=Video and 4=PDF)
  40. switch ($mimeType){
  41. case "text/css":
  42. $typeId = 1; $valid = 1;
  43. break;
  44. case "image/gif":
  45. $typeId = 2; $valid = 1;
  46. break;
  47. case "image/png":
  48. $typeId = 2; $valid = 1;
  49. break;
  50. case "image/jpg":
  51. $typeId = 2; $valid = 1;
  52. break;
  53. case "image/jpeg":
  54. $typeId = 2; $valid = 1;
  55. break;
  56. case "image/pjpeg":
  57. $typeId = 2; $valid = 1;
  58. break;
  59. case "video/mpeg":
  60. $typeId = 3; $valid = 1;
  61. break;
  62. case "video/quicktime":
  63. $typeId = 3; $valid = 1;
  64. break;
  65. case "video/x-msvideo":
  66. $typeId = 3; $valid = 1;
  67. break;
  68. case "video/3gpp":
  69. $typeId = 3; $valid = 1;
  70. break;
  71. case "video/x-flv":
  72. $typeId = 3; $valid = 1;
  73. break;
  74. case "application/pdf":
  75. $typeId = 4; $valid = 1;
  76. break;
  77. case "application/x-pdf":
  78. $typeId = 4; $valid = 1;
  79. break;
  80. case "application/acrobat":
  81. $typeId = 4; $valid = 1;
  82. break;
  83. case "applications/vnd.pdf":
  84. $typeId = 4; $valid = 1;
  85. break;
  86. case "text/pdf":
  87. $typeId = 4; $valid = 1;
  88. break;
  89. case "text/x-pdf":
  90. $typeId = 4; $valid = 1;
  91. break;
  92. case "application/x-download":
  93. $typeId = 4; $valid = 1;
  94. break;
  95. }
  96. $res['valid'] = $valid;
  97. $res['typeId'] = $typeId;
  98. return $res;
  99. }
  100. public function deleteSelectedRows(){
  101. $res = array();
  102. $res['status'] = 0;
  103. if(isset($_POST['id']) && !empty($_POST['id'])){
  104. $papiCall = $_POST['papiCall'];
  105. $id =explode(",", $_POST['id']);
  106. for($i=0; $i<count($id); $i++){
  107. $this->papiCall("POST", $papiCall, array("ID"=>$id[$i]));
  108. }
  109. $res['status'] = 1;
  110. }
  111. print_r(json_encode($res));
  112. }
  113. # Message Composer
  114. public function composeMessage(){
  115. $messageArray[] = array("id" => 31, "name" => "Ok, I totally scewed up");
  116. $messageArray[] = array("id" => 32, "name" => "I'm Sorry");
  117. $messageArray[] = array("id" => 33, "name" => "You're Awesome");
  118. $messageArray[] = array("id" => 34, "name" => "You're Alright");
  119. $messageArray[] = array("id" => 35, "name" => "I Luv Ya Man");
  120. $messageArray[] = array("id" => 36, "name" => "What I Like About You");
  121. $messageArray[] = array("id" => 37, "name" => "I could use a boost");
  122. $messageArray[] = array("id" => 38, "name" => "High Five");
  123. $messageArray[] = array("id" => 39, "name" => "Thinking of you today");
  124. $messageArray[] = array("id" => 40, "name" => "I Love You");
  125. $messageArray[] = array("id" => 41, "name" => "You Rock");
  126. $messageArray[] = array("id" => 42, "name" => "If I haven't told you lately");
  127. $data['messageCounter'] = count($messageArray);
  128. $data['messages'] = $messageArray;
  129. $this->load->view('moodlifter/messageComposer.zpt', $data);
  130. }
  131. # Alert Messages
  132. # Add message
  133. public function addMessage(){
  134. $newMessage = true;
  135. $data['newMessage'] = $newMessage;
  136. $this->load->view('moodlifter/messageForm.zpt', $data);
  137. }
  138. # Edit message
  139. public function editMessage(){
  140. $newMessage = false;
  141. if(isset($_GET['sectionId'])){
  142. $sectionId = $_GET['sectionId'];
  143. $message = "hello world!";
  144. $params['method'] = "GET";
  145. $params['papiCall'] = "Section.Get";
  146. $url = "http://iagh.solucientinc.com";
  147. $messageArray = array();
  148. $params['data'] = array("ID"=>$sectionId);
  149. $this->curl->baseUrl = $url;
  150. $this->curl->PAPIConfig($params);
  151. $res = $this->curl->execute();
  152. $res = json_decode($res['message']);
  153. $messageArray = array("id" => $res->Section->ID, "name" => $res->Section->Name);
  154. }
  155. $data['message'] = $messageArray;
  156. $data['newMessage'] = $newMessage;
  157. $this->load->view('moodlifter/messageForm.zpt', $data);
  158. }
  159. # Save message
  160. public function saveMessage(){
  161. if(isset($_GET['sectionId'])){
  162. $sectionId = $_GET['sectionId'];
  163. $message = "hello world!";
  164. $params['method'] = "GET";
  165. $params['papiCall'] = "Section.Update";
  166. $url = "http://iagh.solucientinc.com";
  167. $messageArray = array();
  168. $params['data'] = array("ID"=>$sectionId);
  169. $this->curl->baseUrl = $url;
  170. $this->curl->PAPIConfig($params);
  171. }
  172. }
  173. public function viewSubCategory(){
  174. $data = array();
  175. $sectionId = 0;
  176. if(isset($_GET['sectionId'])){
  177. $sectionId = $_GET['sectionId'];
  178. $options = array();
  179. $options = array("SectionID"=>$sectionId);
  180. /* $papiResult = $this->papiCall("GET", "Message.GetBySection", $options);
  181. if($papiResult->Status){
  182. $data['subcategories'] = $papiResult->Messages;
  183. }
  184. */
  185. $papiResult = $this->papiCall("GET", "SubSection.GetAll", $options);
  186. if($papiResult->Status){
  187. $data['subcategories'] = $papiResult->SubSections;
  188. }
  189. }
  190. $data['sectionId'] = $sectionId;
  191. $this->load->view('moodlifter/subcategory.zpt', $data);
  192. }
  193. public function addSubCategory(){
  194. $data['isAddRequest'] = true;
  195. $data['subcategoryId'] = 0;
  196. $data['sectionId'] = $_GET['sectionId'];
  197. $this->load->view('moodlifter/subCategoryForm.zpt', $data);
  198. }
  199. public function editSubCategory(){
  200. $sectionId = isset($_GET['sectionId'])?$_GET['sectionId']:0;
  201. $subcategoryId = 0;
  202. if(isset($_GET['subcategoryId'])){
  203. $subcategoryId = $_GET['subcategoryId'];
  204. $options = array();
  205. $options = array("ID"=>$subcategoryId);
  206. // $papiResult = $this->papiCall("GET", "Message.GET", $options);
  207. // $data['message'] = $papiResult->Message;
  208. $papiResult = $this->papiCall("GET", "SubSection.GET", $options);
  209. $data['message'] = $papiResult->SubSection;
  210. }
  211. $data['isAddRequest'] = false;
  212. $data['sectionId'] = $sectionId;
  213. $data['subcategoryId'] = $subcategoryId;
  214. $this->load->view('moodlifter/subCategoryForm.zpt', $data);
  215. }
  216. # js call: genAjaxPost
  217. public function saveSubCategory(){
  218. $res = array();
  219. $res['status'] = 0;
  220. $res['message'] = "";
  221. if(!empty($_POST['data'])){
  222. $dataParams = array();
  223. $post = $_POST['data'];
  224. $param = json_decode($post);
  225. foreach ($param as $item){
  226. $dataParams[$item->name] = $item->value;
  227. }
  228. $sectionId = $dataParams['sectionId'];
  229. $subcategoryId = $dataParams['subcategoryId'];
  230. $subject = $dataParams['subject'];
  231. // $message = $dataParams['message'];
  232. $options = array();
  233. if($subcategoryId){
  234. /*
  235. $options = array(
  236. "ID"=>$subcategoryId,
  237. "Subject"=>$subject,
  238. "Message"=>$message,
  239. "SectionID"=>$sectionId,
  240. "TypeID"=>2,
  241. "LocationID"=>4
  242. );
  243. $papiResult =$this->papiCall("POST","Message.Update",$options);
  244. */
  245. $options = array(
  246. "ID"=>$subcategoryId,
  247. "Name"=>$subject,
  248. "SectionID"=>$sectionId
  249. );
  250. $papiResult =$this->papiCall("POST","SubSection.Update",$options);
  251. $res['message'] = "Changes has been successfully saved";
  252. }
  253. else{
  254. /*
  255. $options = array(
  256. "SectionID"=>$sectionId,
  257. "Subject"=>$subject,
  258. "Message"=>$message,
  259. "TypeID"=>2,
  260. "LocationID"=>4
  261. );
  262. $papiResult = $this->papiCall("POST","Message.Create",$options);
  263. */
  264. $options = array(
  265. "SectionID"=>$sectionId,
  266. "Name"=>$subject
  267. );
  268. $papiResult = $this->papiCall("POST","SubSection.Create",$options);
  269. $res['message'] = "Sub-category has been successfully saved";
  270. }
  271. if($papiResult->Status)
  272. $res['status'] = 1;
  273. }
  274. print_r(json_encode($res));
  275. }
  276. public function addAlertMessage(){
  277. $sectionId = $_GET['sectionId'];
  278. $data['originatingPage'] = $_GET['originatingPage'];
  279. $data['sectionId'] = $sectionId;
  280. $data['isAddRequest'] = true;
  281. $this->load->view('moodlifter/messageAlertForm.zpt', $data);
  282. }
  283. public function editAlertMessage(){
  284. $data['isAddRequest'] = false;
  285. $messages = array();
  286. if(isset($_GET)){
  287. $originationPage = $_GET['originatingPage'];
  288. $sectionId = $_GET['sectionId'];
  289. $messageId = $_GET['messageId'];
  290. $papiResult = $this->papiCall("GET", "Message.Get", array("ID"=>$messageId));
  291. if($papiResult->Status){
  292. $messages = $papiResult->Message;
  293. }
  294. }
  295. $data['sectionId'] = $sectionId;
  296. $data['originatingPage'] = $originationPage;
  297. $data['message'] = $messages;
  298. $this->load->view('moodlifter/messageAlertForm.zpt', $data);
  299. }
  300. # js call: genAjaxPost
  301. public function saveAlertMessage(){
  302. $res = array();
  303. $res['status'] = 0;
  304. $res['message'] = "";
  305. if(!empty($_POST['data'])){
  306. $dataParams = array();
  307. $post = $this->input->post('data');
  308. $param = json_decode($post);
  309. foreach ($param as $item){
  310. $dataParams[$item->name] = $item->value;
  311. }
  312. $sectionId = $dataParams['sectionId'];
  313. $subject = $dataParams['subject'];
  314. $message = $dataParams['message'];
  315. $nameKey = "";
  316. switch ($sectionId){
  317. case 3:
  318. $nameKey = "Moodlifter.Generic";
  319. break;
  320. case 4:
  321. $nameKey = "Moodlifter.FiveToThrive";
  322. break;
  323. case 5:
  324. $nameKey = "Moodlifter.Challenges";
  325. break;
  326. }
  327. # Edit Request
  328. if($dataParams['messageId'] > 0){
  329. $messageId = $dataParams['messageId'];
  330. $papiResult = $this->papiCall("POST", "Message.Update", array("ID"=>$messageId, "Subject"=>$subject, "Message"=>$message));
  331. }
  332. # Add Request
  333. else{
  334. $papiResult = $this->papiCall("POST", "Message.Create", array( "SectionID"=>$sectionId,
  335. "Subject"=>$subject,
  336. "Message"=>$message,
  337. "TypeID"=>2,
  338. "LocationID"=>4
  339. ));
  340. # create alert
  341. if($papiResult->Status){
  342. $papiResult = $this->papiCall("POST", "Alert.Create", array("WorkspaceID"=>$this->workspaceId, "MessageID"=>$papiResult->Message->ID, "NameKey"=>$nameKey));
  343. }
  344. }
  345. $res['status'] = $papiResult->Status + 0;
  346. if($res['status']){
  347. $res['message'] = "Message Alert has been saved successfully!";
  348. }
  349. }
  350. print_r(json_encode($res));
  351. }
  352. public function messageAlert(){
  353. $options = array();
  354. $sectionID = 3;
  355. $options = array("SectionID"=>$sectionID);
  356. $messages = array();
  357. $messageCount = 0;
  358. $papiResult = $this->papiCall("GET", "Message.GetBySection", $options);
  359. if($papiResult->Status){
  360. $messages = $papiResult->Messages;
  361. $messageCount = 1;
  362. }
  363. $data['originatingPage'] = "messageAlert";
  364. $data['sectionId'] = $sectionID;
  365. $data['messages'] = $messages;
  366. $data['messageCount'] = $messageCount;
  367. $this->load->view('moodlifter/messageAlert.zpt', $data);
  368. }
  369. public function fiveForThriveAlert(){
  370. $options = array();
  371. $sectionID = 4;
  372. $options = array("SectionID"=>$sectionID);
  373. $messages = array();
  374. $messageCount = 0;
  375. $papiResult = $this->papiCall("GET", "Message.GetBySection", $options);
  376. if($papiResult->Status){
  377. $messages = $papiResult->Messages;
  378. $messageCount = 1;
  379. }
  380. $data['sectionId'] = $sectionID;
  381. $data['originatingPage'] = "fiveForTriveAlert";
  382. $data['messageCount'] = $messageCount;
  383. $data['messages'] = $messages;
  384. $this->load->view('moodlifter/fiveForThriveAlert.zpt', $data);
  385. }
  386. public function challengeAlert(){
  387. $options = array();
  388. $sectionID = 5;
  389. $options = array("SectionID"=>$sectionID);
  390. $messages = array();
  391. $messageCount = 0;
  392. $papiResult = $this->papiCall("GET", "Message.GetBySection", $options);
  393. if($papiResult->Status){
  394. $messages = $papiResult->Messages;
  395. $messageCount = 1;
  396. }
  397. $data['sectionId'] = $sectionID;
  398. $data['originatingPage'] = "challengeAlert";
  399. $data['messageCount'] = $messageCount;
  400. $data['messages'] = $messages;
  401. $this->load->view('moodlifter/challengeAlert.zpt', $data);
  402. }
  403. public function goodNewsVideoItems(){
  404. $sectionId = 73;
  405. $options = array("WorkspaceID" => $this->workspaceId, "TypeID"=>3, "SectionID"=>$sectionId);
  406. $res = $this->papiCall("GET", "Content.GetAll", $options);
  407. $data['videos'] = $res->Content;
  408. $this->load->view('moodlifter/goodNewsVideoItems.zpt', $data);
  409. }
  410. public function goodNewsAddVideo(){
  411. $data['isAddRequest'] = true;
  412. $data['workspaceId'] = $this->workspaceId;
  413. $data['videoId'] = 0;
  414. $this->load->view('moodlifter/goodNewsVideoForm.zpt', $data);
  415. }
  416. public function editGoodNewsVideo(){
  417. $data = array();
  418. if(isset($_GET['id'])){
  419. $videoId = $_GET['id'];
  420. $options = array("ID"=>$videoId);
  421. $res = $this->papiCall("GET", "Content.Get", $options);
  422. $data['videoId'] = $videoId;
  423. $data['video'] = $res->Video;
  424. $data['isAddRequest'] = false;
  425. }
  426. $this->load->view('moodlifter/goodNewsVideoForm.zpt', $data);
  427. }
  428. # js call: genAjaxPost()
  429. public function saveGoodNewsVideo(){
  430. $res = array();
  431. $res['status'] = 0;
  432. $res['message'] = "";
  433. if(isset($_POST['data'])){
  434. $param = array();
  435. $post = $this->input->post('data');
  436. $param = json_decode($post);
  437. $dataParams = array();
  438. foreach($param as $item){
  439. $dataParams[$item->name] = $item->value;
  440. }
  441. $videoId = $dataParams['videoId'] + 0;
  442. $name = $dataParams['title'];
  443. $description = $dataParams['description'];
  444. $url = $dataParams['url'];
  445. $thumbnailUrl = $dataParams['thumbnailUrl'];
  446. $sectionId = 73;
  447. $typeId = 3; # TypeId for Video
  448. # edit video
  449. if($videoId>0){
  450. $options = array("ID"=>$videoId, "WorkspaceID"=>$this->workspaceId, "Status"=>1, "Name"=>$name, "Description"=>$description, "URL"=>$url, "ThumbnailURL"=>$thumbnailUrl);
  451. $papiResult = $this->papiCall("POST", "Content.Update", $options);
  452. if($papiResult->Status){
  453. $res['status'] = 1;
  454. $res['message'] = "Changes in video details had been successfully saved";
  455. }
  456. }
  457. # add new video
  458. else{
  459. $options = array("TypeID"=>$typeId, "Status"=>1, "Description"=>$description, "Name"=>$name, "URL"=>$url, "ThumbnailURL"=>$thumbnailUrl, "WorkspaceID"=>$this->workspaceId, "SectionID"=>$sectionId);
  460. $papiResult = $this->papiCall("POST", "Content.Create", $options);
  461. if($papiResult->Status){
  462. $res['status'] = 1;
  463. $res['message'] = "You have successfully added a good news video.";
  464. }
  465. }
  466. }
  467. print_r(json_encode($res));
  468. }
  469. public function goodNewsPlaylist(){
  470. $playlist = array();
  471. $data = array();
  472. $options = array("WorkspaceID"=>$this->workspaceId);
  473. $papiResults = $this->papiCall("GET", "Playlist.GetAll", $options);
  474. if($papiResults->Status){
  475. $data['playlists'] = $papiResults->Playlist;
  476. }
  477. $this->load->view('moodlifter/goodNewsPlaylist.zpt', $data);
  478. }
  479. public function addGoodNewsPlaylist(){
  480. $sectionId = 73;
  481. $data = array();
  482. $videos = array();
  483. $data['formType'] = "add";
  484. $dataTable = "";
  485. $options =array("TypeID"=>3, "WorkspaceID"=>$this->workspaceId, "SectionID"=>$sectionId);
  486. $papiResults = $this->papiCall("GET", "Content.GetAll", $options);
  487. if($papiResults->Status){
  488. $videos = $papiResults->Content;
  489. for($i=0; $i<count($videos); $i++){
  490. $dataTable .= '<tr><td><input type="checkbox" name="' . ucwords($videos[$i]->Name) . '" id="video-list" value="'.$videos[$i]->ID.'"/>&nbsp;' . ucwords($videos[$i]->Name) . '</td></tr>';
  491. }
  492. }
  493. $data['dataTable'] = $dataTable;
  494. $this->load->view('moodlifter/goodNewsPlaylistForm.zpt', $data);
  495. }
  496. public function editGoodNewsPlaylist(){
  497. $data = array();
  498. $sectionId = 73;
  499. $dataTable = "";
  500. $playlist = array();
  501. $arrayCurrentVideoList = array();
  502. $currentVideoList = "";
  503. $options = array();
  504. if(isset($_GET['id'])){
  505. $playlistId = $_GET['id'];
  506. $options = array("ID"=>$playlistId);
  507. $papiResults = $this->papiCall("GET", "Playlist.Get", $options);
  508. if($papiResults->Status){
  509. $playlist = $papiResults->Playlist;
  510. $options = array();
  511. $options = array("PlaylistID"=>$playlistId);
  512. $papiResult = $this->papiCall("GET", "Playlist.Content.GetAll", $options);
  513. if($papiResult->Status){
  514. $videoIds = array();
  515. for($i=0; $i<count($papiResult->PlaylistContent); $i++){
  516. $videoIds[] = $papiResult->PlaylistContent[$i]->ID;
  517. $arrayCurrentVideoList [] = '<li class="ui-state-default" id="vlist" name="'.$papiResult->PlaylistContent[$i]->ID.'"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>'. ucwords($papiResult->PlaylistContent[$i]->Name) . ' </li>';
  518. }
  519. $data['strVideoId'] = implode(",",$videoIds);
  520. $papiResult = $this->papiCall("GET", "Content.GetAll", array("TypeID"=>3, "WorkspaceID"=>$this->workspaceId, "SectionID"=>$sectionId));
  521. if($papiResult->Status){
  522. $videos = $papiResult->Content;
  523. for($i=0; $i<count($videos); $i++){
  524. $check = in_array($videos[$i]->ID, $videoIds)?"checked":"";
  525. // if(in_array($videos[$i]->ID, $videoIds)){
  526. // $currentVideoList .= '<div id="video-box" style="margin-left:30px;"><input type="checkbox" name="assignedVideo" id="assignedVideo" checked" disabled="true"/>&nbsp;&nbsp;'.$videos[$i]->Name.'<input type="hidden" name="video-list-hidden" id="video-list-hidden" value="'. ucwords($videos[$i]->Name) .'"/></div>';
  527. // }
  528. $dataTable .= '<tr><td><input type="checkbox" name="' . ucwords($videos[$i]->Name) . '" id="video-list" '.$check.' value="'.$videos[$i]->ID.'"/>&nbsp;' . ucwords($videos[$i]->Name) . '</td></tr>';
  529. }
  530. }
  531. $currentVideoList = implode("", $arrayCurrentVideoList);
  532. }
  533. }
  534. }
  535. $data['playlist'] = $playlist;
  536. $data['formType'] = "edit";
  537. $data['dataTable'] = $dataTable;
  538. $data['currentVideoList'] = $currentVideoList;
  539. $this->load->view('moodlifter/goodNewsPlaylistForm.zpt', $data);
  540. }
  541. public function saveGoodNewsPlaylist(){
  542. $res = array();
  543. $res['status'] = 0;
  544. # Edit Playlist
  545. if(($_POST['playlistId'])){
  546. $playlistId = isset($_POST['playlistId'])?$_POST['playlistId']:"";
  547. $name = isset($_POST['title'])?$_POST['title']:"";
  548. $description = isset($_POST['description'])?$_POST['description']:"";
  549. $videoId = isset($_POST['videoId'])?$_POST['videoId']:"";
  550. $workspaceId = $this->workspaceId;
  551. $options = array(
  552. "ID"=>$playlistId,
  553. "Name"=>$name,
  554. "Description"=>$description,
  555. "WorkspaceID"=>$workspaceId
  556. );
  557. $papiResult = $this->papiCall("POST", "Playlist.Update", $options);
  558. if($papiResult->Status){
  559. $currentVideoId = isset($_POST['currentVideoId'])?$_POST['currentVideoId']:"";
  560. # delete current videos in playlist
  561. if(!empty($currentVideoId)){
  562. $this->papiCall("POST", "Playlist.Content.Remove", array("ContentID"=>$currentVideoId, "PlaylistID"=>$playlistId));
  563. }
  564. if($videoId != "0"){
  565. if($papiResult->Status){
  566. # add new list of videos
  567. $papiResult = $this->papiCall("POST", "Playlist.Content.Add", array("PlaylistID"=>$playlistId, "ContentID"=>$videoId));
  568. }
  569. $res['status'] = $papiResult->Status + 0;
  570. }
  571. else{
  572. $res['status'] = 1;
  573. }
  574. }
  575. else {
  576. $res['status'] = $papiResult->Status + 0;
  577. }
  578. }
  579. # Add Playlist
  580. else{
  581. $name = $_POST['title'];
  582. $description = $_POST['description'];
  583. $videoId = $_POST['videoId'];
  584. $status = 0;
  585. $workspaceId = $this->workspaceId;
  586. $options = array(
  587. "Name"=>$name,
  588. "Description"=>$description,
  589. "Status"=>$status,
  590. "WorkspaceID"=>$workspaceId
  591. );
  592. $papiResults = $this->papiCall("POST", "Playlist.Create", $options);
  593. $playlistId = $papiResults->Playlist->ID;
  594. $videoIds = explode(",", $videoId);
  595. for($i=0; $i<count($videoIds); $i++){
  596. $options = array();
  597. $options = array(
  598. "PlaylistID"=>$playlistId,
  599. "ContentID"=>$videoIds[$i]
  600. );
  601. $this->papiCall("POST", "Playlist.Content.Add", $options);
  602. }
  603. $res['status'] = 1;
  604. }
  605. print_r(json_encode($res));
  606. }
  607. public function publishGoodNewsPlaylist(){
  608. $res = array();
  609. $res['status'] = 0;
  610. if(isset($_POST)){
  611. $currentPublishedId = explode(",", $_POST['playlistId']);
  612. $papiResult = $this->papiCall("GET", "Playlist.GetAll", array("WorkspaceID"=>$this->workspaceId));
  613. if($papiResult->Status){
  614. $playlistId = $papiResult->Playlist;
  615. for($i=0; $i<count($playlistId); $i++){
  616. if(in_array($playlistId[$i]->ID, $currentPublishedId)){
  617. $this->papiCall("POST", "Playlist.Update", array("ID"=>$playlistId[$i]->ID, "Status"=>1));
  618. }
  619. else {
  620. $this->papiCall("POST", "Playlist.Update", array("ID"=>$playlistId[$i]->ID, "Status"=>0));
  621. }
  622. }
  623. }
  624. $res['status'] = 1;
  625. }
  626. print_r(json_encode($res));
  627. }
  628. public function secretVault(){
  629. $secretVault = array();
  630. $data = array();
  631. $options = array("WorkspaceID"=>$this->workspaceId);
  632. $papiResult = $this->papiCall("GET", "Vault.GetAll", $options);
  633. if($papiResult->Status){
  634. $data['vaults'] = $papiResult->Vaults;
  635. }
  636. $this->load->view('moodlifter/secretVault.zpt', $data);
  637. }
  638. public function addSecretVault(){
  639. $sectionId = 75;
  640. $data = array();
  641. $data['isAddRequest'] = true;
  642. $dataTable = "";
  643. $papiResult = $this->papiCall("GET", "Content.GetAll", array("WorkspaceID"=>$this->workspaceId, "SectionID"=>$sectionId));
  644. if($papiResult->Status){
  645. $videos = $papiResult->Content;
  646. for($i=0; $i<count($videos); $i++){
  647. $dataTable .= '<tr><td><input type="checkbox" name="' . ucwords($videos[$i]->Name) . '" id="vault-list" value="'.$videos[$i]->ID.'"/>&nbsp;' . ucwords($videos[$i]->Name) . '</td></tr>';
  648. }
  649. }
  650. $data['dataTable'] = $dataTable;
  651. $this->load->view('moodlifter/secretVaultForm.zpt', $data);
  652. }
  653. public function addSecretVaultItems(){
  654. $sectionId = 75;
  655. $data = array();
  656. $data['sectionId'] = $sectionId;
  657. $this->load->view('moodlifter/vaultItemsForm.zpt', $data);
  658. }
  659. public function saveVaultItems(){
  660. $res = array();
  661. $error = "";
  662. $res['status'] = 0;
  663. $sectionId = 75;
  664. if(!empty($_POST['name']) && !empty($_POST['description'])){
  665. $videoUrl = $_POST['videoUrl'];
  666. $name = $_POST['name'] = $_POST['name'];
  667. $description = $_POST['description'];
  668. $thumbnail = $_POST['thumbnail'];
  669. $workspaceId = $this->workspaceId;
  670. if($videoUrl != "" || $thumbnail != ""){
  671. $papiResult = $this->papiCall("POST", "Content.Create", array("TypeID"=>3, "Status"=>1, "Description"=>$description, "Name"=>$name, "URL"=>$videoUrl, "WorkspaceID"=>$workspaceId, "SectionID"=>$sectionId, "ThumbnailURL"=>$thumbnail));
  672. $res['status'] = $papiResult->Status + 0;
  673. }
  674. else{
  675. $fileElementName = 'uploader';
  676. if(!empty($_FILES[$fileElementName]['error'])){
  677. switch($_FILES[$fileElementName]['error'])
  678. {
  679. case '1':
  680. $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
  681. break;
  682. case '2':
  683. $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
  684. break;
  685. case '3':
  686. $error = 'The uploaded file was only partially uploaded';
  687. break;
  688. case '4':
  689. $error = 'No file was uploaded.';
  690. break;
  691. case '6':
  692. $error = 'Missing a temporary folder';
  693. break;
  694. case '7':
  695. $error = 'Failed to write file to disk';
  696. break;
  697. case '8':
  698. $error = 'File upload stopped by extension';
  699. break;
  700. case '999':
  701. default:
  702. $error = 'No error code avaiable';
  703. }
  704. }
  705. elseif(empty($_FILES['uploader']['tmp_name']) || $_FILES['uploader']['tmp_name'] == 'none'){
  706. $error = 'No file was uploaded..';
  707. }
  708. else {
  709. if (file_exists("uploads/" . $_FILES["uploader"]["name"])){
  710. $error = $_FILES["uploader"]["name"] . " already exists. ";
  711. }
  712. else{
  713. $mimeTypes = $this->verifyMimeType($_FILES['uploader']['type']);
  714. if($mimeTypes['valid']){
  715. if(move_uploaded_file($_FILES["uploader"]["tmp_name"],"uploads/" . $_FILES["uploader"]["name"])){
  716. $typeId = $mimeTypes['typeId'];
  717. $url = base_url() ."uploads/" . $_FILES['uploader']['name'];
  718. $papiResult = $this->papiCall("POST", "Content.Create", array("TypeID"=>$typeId, "Status"=>1, "Description"=>$description, "Name"=>$name, "URL"=>$url, "WorkspaceID"=>$workspaceId, "SectionID"=>$sectionId, "ThumbnailURL"=>$thumbnail));
  719. if($papiResult->Status){
  720. $res['status'] = 1;
  721. }
  722. else {
  723. $res['status'] = 0;
  724. # remove uploaded file
  725. @unlink("uploads/" .$_FILES['uploader']['name']);
  726. }
  727. }
  728. else{
  729. $error = "Unable to upload file!";
  730. }
  731. }
  732. else{
  733. $error = "Cannot upload the file. The format is not supported";
  734. }
  735. }
  736. }
  737. }
  738. }
  739. else {
  740. $error = "Fill all required fields";
  741. }
  742. $res['error'] = $error;
  743. print_r(json_encode($res));
  744. }
  745. public function editSecretVault(){
  746. $sectionId = 75;
  747. $data = array();
  748. $vaultDetails = array();
  749. $vaultItems = array();
  750. $currentVaultList = "";
  751. $dataTable = "";
  752. if($_GET['id']){
  753. $vaultId = $_GET['id'];
  754. $papiResult = $this->papiCall("GET", "Vault.Content.GetAll", array("VaultID"=>$vaultId));
  755. if($papiResult->Status){
  756. $vaultDetails = $papiResult->Vault;
  757. $vaultItems = $papiResult->VaultItems;
  758. $vaultIds = array();
  759. for($i=0; $i<count($vaultItems); $i++){
  760. $vaultIds[] = $vaultItems[$i]->ID;
  761. }
  762. $data['strVaultId'] = implode(",",$vaultIds);
  763. $papiResult = $this->papiCall("GET", "Content.GetAll", array("WorkspaceID"=>$this->workspaceId, "SectionID"=>$sectionId));
  764. if($papiResult->Status){
  765. $videos = $papiResult->Content;
  766. for($i=0; $i<count($videos); $i++){
  767. $check = in_array($videos[$i]->ID, $vaultIds)?"checked":"";
  768. if(in_array($videos[$i]->ID, $vaultIds)){
  769. $currentVaultList .= '<div id="vault-box" style="margin-left:30px;"><input type="checkbox" name="assignedVaultItems" id="assignedVaultItems" checked disabled="true"/>&nbsp;&nbsp;'.$videos[$i]->Name.'<input type="hidden" name="video-list-hidden" id="video-list-hidden" value="'. ucwords($videos[$i]->Name) .'"/></div>';
  770. }
  771. $dataTable .= '<tr><td><input type="checkbox" name="' . ucwords($videos[$i]->Name) . '" id="vault-list" '.$check.' value="'.$videos[$i]->ID.'"/>&nbsp;' . ucwords($videos[$i]->Name) . '</td></tr>';
  772. }
  773. }
  774. }
  775. }
  776. $data['isAddRequest'] = false;
  777. $data['vault'] = $vaultDetails;
  778. $data['vaultItems'] = $vaultItems;
  779. $data['dataTable'] = $dataTable;
  780. $data['currentVaultList'] = $currentVaultList;
  781. $this->load->view("moodlifter/secretVaultForm.zpt", $data);
  782. }
  783. public function saveSecretVault(){
  784. $res = array();
  785. $res['status'] = 0;
  786. $name = isset($_POST['title'])?$_POST['title']:"";
  787. $description = isset($_POST['description'])?$_POST['description']:"";
  788. $token = isset($_POST['token'])?$_POST['token']:"";
  789. $currentVaultId = isset($_POST['currentVaultId'])?trim($_POST['currentVaultId']):"";
  790. $imageUrl = isset($_POST['imageUrl'])?$_POST['imageUrl']:"";
  791. $newVaultItems = isset($_POST['vaultItems'])?trim($_POST['vaultItems']):"";
  792. $workspaceId = $this->workspaceId;
  793. # edit request for secret vault
  794. if(isset($_POST['vaultId']) && $_POST['vaultId'] != 0){
  795. # update vault details
  796. $vaultId = trim($_POST['vaultId']) + 0;
  797. $options = array(
  798. "ID"=>$vaultId,
  799. "Name"=>$name,
  800. "Description"=>$description,
  801. "Cost"=>$token,
  802. "ImageURL"=>$imageUrl,
  803. "WorkspaceID"=>$workspaceId
  804. );
  805. $papiResult = $this->papiCall("POST", "Vault.Update", $options);
  806. if($papiResult->Status){
  807. if($currentVaultId !=""){
  808. # delete existing vault items
  809. $papiResult = $this->papiCall("POST", "Vault.Content.Remove", array("ContentID"=>$currentVaultId, "VaultID"=>$vaultId));
  810. $res['status'] = $papiResult->Status + 0;
  811. }
  812. if(!empty($newVaultItems) && $newVaultItems !=""){
  813. # insert new vault items
  814. $papiResult = $this->papiCall("POST", "Vault.Content.Add", array("ContentID"=>$newVaultItems, "VaultID"=>$vaultId, "Status"=>0));
  815. $res['status'] = $papiResult->Status + 0;
  816. }
  817. }
  818. }
  819. # add request for secret vault
  820. else{
  821. $papiResult = $this->papiCall("POST", "Vault.Create", array("Name"=>$name, "ImageURL"=>$imageUrl, "Cost"=>$token, "Status"=>0, "Description"=>$description, "WorkspaceID"=>$workspaceId));
  822. if($papiResult->Status){
  823. # add vault items in secret vault
  824. $vaultId = $papiResult->Vault->ID;
  825. if($vaultId){
  826. if(!empty($newVaultItems) && $newVaultItems !=""){
  827. # insert new vault items
  828. $papiResult = $this->papiCall("POST", "Vault.Content.Add", array("ContentID"=>$newVaultItems, "VaultID"=>$vaultId, "Status"=>0));
  829. $res['status'] = $papiResult->Status + 0;
  830. }
  831. }
  832. }
  833. $res['status'] = $papiResult->Status;
  834. }
  835. print_r(json_encode($res));
  836. }
  837. public function publishSecretVault(){
  838. $res = array();
  839. $res['status'] = 0;
  840. $vaultId = array();
  841. if(isset($_POST)){
  842. $currentPublishedId = explode(",", $_POST['vaultId']);
  843. $papiResult = $this->papiCall("GET", "Vault.GetAll", array("WorkspaceID"=>$this->workspaceId));
  844. if($papiResult->Status){
  845. $vaultId = $papiResult->Vaults;
  846. for($i=0; $i<count($vaultId); $i++){
  847. if(in_array($vaultId[$i]->ID, $currentPublishedId)){
  848. $this->papiCall("POST", "Vault.Update", array("ID"=>$vaultId[$i]->ID, "Status"=>1));
  849. }
  850. else {
  851. $this->papiCall("POST", "Vault.Update", array("ID"=>$vaultId[$i]->ID, "Status"=>0));
  852. }
  853. }
  854. }
  855. $res['status'] = 1;
  856. }
  857. print_r(json_encode($res));
  858. }
  859. public function challenges(){
  860. $sectionId = 74;
  861. $challenges = array();
  862. $data = array();
  863. $options = array("WorkspaceID"=>$this->workspaceId, "ParentID"=>0);
  864. $papiResult = $this->papiCall("GET", "Challenge.GetAll", $options);
  865. if($papiResult->Status){
  866. $data['challenges'] = $papiResult->Challenges;
  867. }
  868. $this->load->view('moodlifter/challenges.zpt', $data);
  869. }
  870. public function addParentChallenge(){
  871. $data = array();
  872. $parentId = 0;
  873. $data['isAddRequest'] = true;
  874. $data['parentId'] = $parentId;
  875. $this->load->view('moodlifter/challengeForm.zpt', $data);
  876. }
  877. public function editParentChallenge(){
  878. $data = array();
  879. $challengeDetails = array();
  880. $parentId = 0;
  881. $data['isAddRequest'] = false;
  882. if(isset($_GET['parentId'])){
  883. $parentId = $_GET['parentId'];
  884. $papiResult = $this->papiCall("GET", "Challenge.Get", array("ID"=>$parentId));
  885. if($papiResult->Status){
  886. $challengeDetails = $papiResult->Challenge;
  887. }
  888. }
  889. $data['challenge'] = $challengeDetails;
  890. $data['parentId'] = $parentId;
  891. $this->load->view('moodlifter/challengeForm.zpt', $data);
  892. }
  893. public function saveParentChallenge(){
  894. $res = array();
  895. $res['status'] = 0;
  896. $res['message'] = "";
  897. if(isset($_POST['data'])){
  898. $post = $this->input->post('data');
  899. $param = json_decode($post);
  900. $dataParams = array();
  901. foreach($param as $item){
  902. $dataParams[$item->name] = $item->value;
  903. }
  904. $parenId = trim($dataParams['parentId']) + 0;
  905. $name = $dataParams['name'] ;
  906. $instruction = $dataParams['instruction'];
  907. $videoInstruction = $dataParams['videoInstruction'];
  908. $avatar = $dataParams['avatar'];
  909. $welcomeMessage = $dataParams['welcomeMessage'];
  910. # edit request
  911. if($parenId){
  912. $papiResult = $this->papiCall("POST", "Challenge.Update", array("ID"=>$parenId, "Name"=>$name, "Instruction"=>$instruction, "VideoInstruction"=>$videoInstruction, "AvatarURL"=>$avatar, "WelcomeMessage"=>$welcomeMessage));
  913. $res['status'] = $papiResult->Status + 0;
  914. }
  915. # add request
  916. else {
  917. $papiResult = $this->papiCall("POST", "Challenge.Create", array("Name"=>$name, "TokenCount"=>0, "Status"=>0, "Instruction"=>$instruction, "VideoInstruction"=>$videoInstruction, "AvatarURL"=>$avatar, "WelcomeMessage"=>$welcomeMessage, "WorkspaceID"=>$this->workspaceId));
  918. $res['status'] = $papiResult->Status + 0;
  919. }
  920. if($res['status']){
  921. $res['message'] = "Challenge has been successfully saved!";
  922. }
  923. }
  924. print_r(json_encode($res));
  925. }
  926. public function publishChallenge(){
  927. $res = array();
  928. $res['status'] = 0;
  929. $vaultId = array();
  930. if(isset($_POST)){
  931. $currentPublishedId = explode(",", $_POST['challengeId']);
  932. $papiResult = $this->papiCall("GET", "Challenge.GetAll", array("WorkspaceID"=>$this->workspaceId));
  933. if($papiResult->Status){
  934. $challenges = $papiResult->Challenges;
  935. for($i=0; $i<count($challenges); $i++){
  936. if(in_array($challenges[$i]->ID, $currentPublishedId)){
  937. $this->papiCall("POST", "Challenge.Update", array("ID"=>$challenges[$i]->ID, "Status"=>1));
  938. }
  939. else {
  940. $this->papiCall("POST", "Challenge.Update", array("ID"=>$challenges[$i]->ID, "Status"=>0));
  941. }
  942. }
  943. }
  944. $res['status'] = 1;
  945. }
  946. print_r(json_encode($res));
  947. }
  948. # deleted in page challenged.zpt ------------
  949. public function subChallenges(){
  950. $data = array();
  951. $sectionId = 74;
  952. $subChallenges = array();
  953. $parentChallenges = array();
  954. $dataTable = array();
  955. $workspaceId = $this->workspaceId;
  956. $papiResult = $this->papiCall("GET", "Challenge.GetAll", array(""));
  957. if($papiResult->Status){
  958. $challenges = $papiResult->Challenges;
  959. for($i=0; $i<count($challenges); $i++){
  960. if($challenges[$i]->ParentID>0){
  961. $subChallenges[] = array( "ID"=>$challenges[$i]->ID,
  962. "Name"=>$challenges[$i]->Name,
  963. "TokenCount"=>$challenges[$i]->TokenCount,
  964. "ParentID"=>$challenges[$i]->ParentID
  965. );
  966. }
  967. else{
  968. $parentChallenges[] = array("ID"=>$challenges[$i]->ID, "Name"=>$challenges[$i]->Name);
  969. }
  970. }
  971. }
  972. if(!empty($subChallenges)){
  973. for($i=0; $i<count($subChallenges); $i++){
  974. $dataTable[] = "<tr>";
  975. $sel = "<select id='parentChallenge'>";
  976. for($j=0; $j<count($parentChallenges); $j++){
  977. $selected = $subChallenges[$i]['ParentID'] == $parentChallenges[$j]['ID']?"selected='selected'":"";
  978. $sel .= "<option value='{$subChallenges[$i]['ID']}|{$parentChallenges[$j]['ID']}' {$selected} >{$parentChallenges[$j]['Name']}</option>";
  979. }
  980. $sel .="</select>";
  981. $dataTable[] = "<td><input type='checkbox' name='pubChk' id='pubChk' value='{$subChallenges[$i]['ID']}' /> &nbsp;";
  982. $dataTable[] = "<span onmouseover=\"moodlifter.displayButtons('subCat{$subChallenges[$i]['ID']}')\">{$subChallenges[$i]['Name']}</span>";
  983. $dataTable[] = "<div class=\"subCat{$subChallenges[$i]['ID']}\" style=\"display:none; width:400px; height:40px; margin-top:10px;\">";
  984. $dataTable[] = "<a href=\"#/moodlifter/editSubChallenge/?subChallengeId={$subChallenges[$i]['ID']}\" class=\"button icon-with-text\" title=\"Edit Challenge\"><img src=\"/images/navicons-small/135.png\" alt=\"\"/>Edit SubChallenge</a>&nbsp;";
  985. $dataTable[] = "<a href=\"#\" class=\"button icon-with-text\" title=\"Close\" onclick=\"moodlifter.hideButtons('subCat{$subChallenges[$i]['ID']}')\"><img src=\"/images/navicons-small/134.png\" alt=\"\"/>Close</a></div></td>";
  986. $dataTable[] = "<td>{$subChallenges[$i]['TokenCount']}</td>";
  987. $dataTable[] = "<td>{$sel}</td>";
  988. $dataTable[] = "</tr>";
  989. }
  990. }
  991. $data['subChallenges'] = $subChallenges;
  992. $data['dataTable'] = implode("", $dataTable);
  993. $this->load->view('moodlifter/subChallenge.zpt', $data);
  994. }
  995. # deleted in page challenged.zpt ------------
  996. public function viewParentSubChallenges(){
  997. $data = array();
  998. $sectionId = 74;
  999. $subChallenges = array();
  1000. $parentChallenges = array();
  1001. $parentId = 0;
  1002. $dataTable = array();
  1003. if(isset($_GET['parentId'])){
  1004. $parentId = $_GET['parentId'];
  1005. $workspaceId = $this->workspaceId;
  1006. $papiResult = $this->papiCall("GET", "Challenge.GetAll", array(""));
  1007. if($papiResult->Status){
  1008. $challenges = $papiResult->Challenges;
  1009. for($i=0; $i<count($challenges); $i++){
  1010. if($challenges[$i]->ParentID == $parentId){
  1011. $subChallenges[] = array( "ID"=>$challenges[$i]->ID,
  1012. "Name"=>$challenges[$i]->Name,
  1013. "TokenCount"=>$challenges[$i]->TokenCount,
  1014. "ParentID"=>$challenges[$i]->ParentID
  1015. );
  1016. }
  1017. if(!$challenges[$i]->ParentID){
  1018. $parentChallenges[] = array("ID"=>$challenges[$i]->ID, "Name"=>$challenges[$i]->Name);
  1019. }
  1020. }
  1021. }
  1022. }
  1023. if(!empty($subChallenges)){
  1024. for($i=0; $i<count($subChallenges); $i++){
  1025. $dataTable[] = "<tr>";
  1026. $sel = "<select id='parentChallenge'>";
  1027. for($j=0; $j<count($parentChallenges); $j++){
  1028. $selected = $subChallenges[$i]['ParentID'] == $parentChallenges[$j]['ID']?"selected='selected'":"";
  1029. $sel .= "<option value='{$subChallenges[$i]['ID']}|{$parentChallenges[$j]['ID']}' {$selected} >{$parentChallenges[$j]['Name']}</option>";
  1030. }
  1031. $sel .="</select>";
  1032. $dataTable[] = "<td><input type='checkbox' name='pubChk' id='pubChk' value='{$subChallenges[$i]['ID']}' /> &nbsp;";
  1033. $dataTable[] = "<span onmouseover=\"moodlifter.displayButtons('subCat{$subChallenges[$i]['ID']}')\">{$subChallenges[$i]['Name']}</span>";
  1034. $dataTable[] = "<div class=\"subCat{$subChallenges[$i]['ID']}\" style=\"display:none; width:400px; height:40px; margin-top:10px;\">";
  1035. $dataTable[] = "<a href=\"#/moodlifter/editSubChallenge/?subChallengeId={$subChallenges[$i]['ID']}\" class=\"button icon-with-text\" title=\"Edit Challenge\"><img src=\"/images/navicons-small/135.png\" alt=\"\"/>Edit SubChallenge</a>&nbsp;";
  1036. $dataTable[] = "<a href=\"#\" class=\"button icon-with-text\" title=\"Close\" onclick=\"moodlifter.hideButtons('subCat{$subChallenges[$i]['ID']}')\"><img src=\"/images/navicons-small/134.png\" alt=\"\"/>Close</a></div></td>";
  1037. $dataTable[] = "<td>{$subChallenges[$i]['TokenCount']}</td>";
  1038. $dataTable[] = "<td>{$sel}</td>";
  1039. $dataTable[] = "</tr>";
  1040. }
  1041. }
  1042. $data['parentId'] = $parentId;
  1043. $data['subChallenges'] = $subChallenges;
  1044. $data['dataTable'] =implode("", $dataTable);
  1045. $this->load->view('moodlifter/subChallenge.zpt', $data);
  1046. }
  1047. public function addSubChallenge(){
  1048. $data = array();
  1049. $parentId = isset($_GET['parentId'])?$_GET['parentId']:0;
  1050. $parentChallenges = array();
  1051. $selectMenu = array();
  1052. $papiResult = $this->papiCall("GET", "Challenge.GetAll", array("ParentID"=>0));
  1053. if($papiResult->Status){
  1054. $parentChallenges = $papiResult->Challenges;
  1055. $selectMenu[] = "<select id='parentChallenge' name='parentId'>";
  1056. for($i=0; $i<count($parentChallenges); $i++){
  1057. $selected = $parentChallenges[$i]->ID == $parentId?"selected":"";
  1058. $selectMenu[] = "<option value='{$parentChallenges[$i]->ID}' {$selected}>{$parentChallenges[$i]->Name}</option>";
  1059. }
  1060. $selectMenu[] = "</select>";
  1061. }
  1062. $data['isAddRequest'] = true;
  1063. $data['subChallengeId'] = 0;
  1064. $data['parentId'] = $parentId;
  1065. $data['parentMenu'] = implode("", $selectMenu);
  1066. $this->load->view('moodlifter/subChallengeForm.zpt', $data);
  1067. }
  1068. public function editSubChallenge(){
  1069. $data = array();
  1070. $challengeDetails = array();
  1071. $subChallengeId = 0;
  1072. $selectMenu = array();
  1073. $parentChallenges = array();
  1074. $data['isAddRequest'] = false;
  1075. if(isset($_GET['subChallengeId'])){
  1076. $subChallengeId = $_GET['subChallengeId'];
  1077. $papiResult = $this->papiCall("GET", "Challenge.Get", array("ID"=>$subChallengeId));
  1078. if($papiResult->Status){
  1079. $challengeDetails = $papiResult->Challenge;
  1080. $parentId = $challengeDetails->ParentID;
  1081. }
  1082. }
  1083. $papiResult = $this->papiCall("GET", "Challenge.GetAll", array("ParentID"=>0));
  1084. if($papiResult->Status){
  1085. $parentChallenges = $papiResult->Challenges;
  1086. $selectMenu[] = "<select id='parentChallenge' name='parentId'>";
  1087. for($i=0; $i<count($parentChallenges); $i++){
  1088. $selected = $parentChallenges[$i]->ID==$parentId?"selected='selected'":"";
  1089. $selectMenu[] = "<option value='{$parentChallenges[$i]->ID}' {$selected}>{$parentChallenges[$i]->Name}</option>";
  1090. }
  1091. $selectMenu[] = "</select>";
  1092. }
  1093. $data['parentMenu'] = implode("", $selectMenu);
  1094. $data['subChallengeId'] = $subChallengeId;
  1095. $data['challenge'] = $challengeDetails;
  1096. $data['parentId'] = $parentId;
  1097. $this->load->view('moodlifter/subChallengeForm.zpt', $data);
  1098. }
  1099. # js call: genAjaxPost
  1100. public function saveSubChallenge(){
  1101. $res = array();
  1102. $res['status'] = 0;
  1103. $res['message'] = "";
  1104. if(isset($_POST['data'])){
  1105. $post = $this->input->post('data');
  1106. $param = json_decode($post);
  1107. $dataParams = array();
  1108. foreach($param as $item){
  1109. $dataParams[$item->name] = $item->value;
  1110. }
  1111. $parentId = trim($dataParams['parentId']) + 0;
  1112. $name = $dataParams['name'] ;
  1113. $instruction = $dataParams['instruction'];
  1114. $videoInstruction = $dataParams['videoInstruction'];
  1115. $avatar = $dataParams['avatar'];
  1116. $token = $dataParams['token'];
  1117. $subChallengeId = $dataParams['subChallengeId'];
  1118. # edit request
  1119. if($subChallengeId){
  1120. $papiResult = $this->papiCall("POST", "Challenge.Update", array(
  1121. "ID"=>$subChallengeId,
  1122. "Name"=>$name,
  1123. "Instruction"=>$instruction,
  1124. "VideoInstruction"=>$videoInstruction,
  1125. "AvatarURL"=>$avatar,
  1126. "TokenCount"=>$token,
  1127. "ParentID"=>$parentId
  1128. ));
  1129. $res['status'] = $papiResult->Status + 0;
  1130. }
  1131. # add request
  1132. else {
  1133. $papiResult = $this->papiCall("POST", "Challenge.Create", array(
  1134. "Name"=>$name,
  1135. "Instruction"=>$instruction,
  1136. "VideoInstruction"=>$videoInstruction,
  1137. "AvatarURL"=>$avatar,
  1138. "TokenCount"=>$token,
  1139. "Status"=>1,
  1140. "ParentID"=>$parentId,
  1141. "WorkspaceID"=>$this->workspaceId
  1142. ));
  1143. $res['status'] = $papiResult->Status + 0;
  1144. }
  1145. if($papiResult->Status){
  1146. $res['message'] = "Challenges has been successfully saved!";
  1147. }
  1148. }
  1149. print_r(json_encode($res));
  1150. }
  1151. public function applySubChallengeMapping(){
  1152. $res = array();
  1153. $res['status'] = 0;
  1154. if($_POST['id']){
  1155. $id = explode(",", $_POST['id']);
  1156. for($i=0; $i<count($id); $i++){
  1157. $childParentId = explode("|", $id[$i]);
  1158. $childId = $childParentId[0];
  1159. $parentId = $childParentId[1];
  1160. $this->papiCall("POST", "Challenge.Update", array("ID"=>$childId, "ParentID"=>$parentId));
  1161. }
  1162. $res['status'] = 1;
  1163. }
  1164. print_r(json_encode($res));
  1165. }
  1166. }