Advertisement
vDeltaAirlines

Mail.php

Jun 19th, 2013
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.91 KB | None | 0 0
  1. <?php
  2. //AIRMail3
  3. //simpilotgroup addon module for phpVMS virtual airline system
  4. //
  5. //simpilotgroup addon modules are licenced under the following license:
  6. //Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
  7. //To view full icense text visit http://creativecommons.org/licenses/by-nc-sa/3.0/
  8. //
  9. //@author David Clark (simpilot)
  10. //@copyright Copyright (c) 2009-2011, David Clark
  11. //@license http://creativecommons.org/licenses/by-nc-sa/3.0/
  12.  
  13. class Mail extends CodonModule {
  14.  
  15. public function index() {
  16. if(!Auth::LoggedIn()) {
  17. $this->set('message', 'You must be logged in to access this feature!');
  18. $this->render('core_error.tpl');
  19. return;
  20. }
  21. switch($this->post->action){
  22. case 'savefolder':
  23. $this->savefolder();
  24. break;
  25. case 'move':
  26. $this->move();
  27. break;
  28. case 'confirm_delete_folder':
  29. $this->confirm_delete_folder();
  30. break;
  31. case 'confirm_edit_folder':
  32. $this->confirm_edit_folder();
  33. break;
  34. case 'save_settings':
  35. $this->save_settings();
  36. break;
  37. case 'send':
  38. $this->send();
  39. default:
  40. $this->inbox();
  41. }
  42. return;
  43. }
  44.  
  45. //message screen
  46. public function message(){
  47. if(!Auth::LoggedIn()){
  48. $this->set('message', 'You must be logged in to access this feature!');
  49. $this->render('core_error.tpl');
  50. return;
  51. }else{
  52. $this->menu();
  53. $this->show('mail/mail_message.tpl');
  54. }
  55. }
  56.  
  57. //main inbox
  58. public function inbox() {
  59. $this->set('mail', MailData::getallmail(Auth::$userinfo->pilotid));
  60. $this->set('pilotcode', PilotData::GetPilotCode(Auth::$userinfo->code, Auth::$userinfo->pilotid));
  61. $this->menu();
  62. $this->show('mail/mail_inbox.tpl');
  63. }
  64.  
  65. //internal function to show top menu for airmail
  66. public function menu() {
  67. $this->set('folders', MailData::checkforfolders(Auth::$userinfo->pilotid));
  68. $this->show('mail/mail_menu.tpl');
  69. }
  70.  
  71. public function item($thread_id, $who_to = null) {
  72. $who_to = ($who_to == null) ? Auth::$userinfo->pilotid : (int)$who_to;
  73. if(!Auth::LoggedIn()) {
  74. $this->set('message', 'You must be logged in to access this feature!');
  75. $this->render('core_error.tpl');
  76. return;
  77. }
  78. else {
  79. $this->set('mail', MailData::getmailcontent($thread_id, $who_to));
  80. $this->menu();
  81. $this->show('mail/mail_open.tpl');
  82. }
  83. }
  84.  
  85. //create new message
  86. public function newmail() {
  87. if(!Auth::LoggedIn()) {
  88. $this->set('message', 'You must be logged in to access this feature!');
  89. $this->render('core_error.tpl');
  90. return;
  91. }
  92. else {
  93. $this->set('allpilots', $pilots=(PilotData::findPilots(array('p.retired' => '0'))));
  94. $this->menu();
  95. $this->show('mail/mail_new.tpl');
  96. }
  97. }
  98.  
  99. //send new message
  100. protected function send() {
  101. if(!Auth::LoggedIn()) {
  102. $this->set('message', 'You must be logged in to access this feature!');
  103. $this->render('core_error.tpl');
  104. return;
  105. }
  106. $who_to = DB::escape($this->post->who_to);
  107. $who_from = DB::escape($this->post->who_from);
  108. $subject = DB::escape($this->post->subject);
  109. $message = DB::escape($this->post->message);
  110. $oldmessage = DB::escape($this->post->oldmessage);
  111.  
  112. if($oldmessage)
  113. {
  114. $thread_id = $oldmessage;
  115. }
  116. else
  117. {
  118. $thread_id = time();
  119. }
  120.  
  121. if(!$who_to) {
  122. $nosender = 'You must choose a reciepent';
  123. echo '<center><br /><b>'.$nosender.'</b><br /></center>';
  124. $this->inbox();
  125. return;
  126. }
  127.  
  128. if (!$subject) {
  129. $subject = '(No Subject)';
  130. }
  131.  
  132. if($who_to == 'all')
  133. {
  134. $notam = 0;
  135. $pilots=(PilotData::findPilots(array('p.retired' => '0')));
  136. foreach ($pilots as $pilot) {
  137. $notam = $notam+1;
  138. MailData::send_new_mail($pilot->pilotid, $who_from, $subject, $message, $notam, $thread_id);
  139. if(MailData::send_email($pilot->pilotid) === TRUE)
  140. {
  141. $email = $pilot->email;
  142. $sub = 'You have reveived a new message at '.SITE_NAME;
  143. $message = 'You received a new message with the subject ('.$subject.') in your pilot\'s message inbox on '.date('m/d/Y', time());
  144. Util::SendEmail($email, $sub, $message);
  145. }
  146. }
  147. }
  148. else
  149. {
  150. MailData::send_new_mail($who_to, $who_from, $subject, $message, '0', $thread_id);
  151. if(MailData::send_email($who_to) === TRUE)
  152. {
  153. $pilot = PilotData::getPilotData($who_to);
  154. $email = $pilot->email;
  155. $sub = 'You have reveived a new message at '.SITE_NAME;
  156. $message = 'You received a new message with the subject ('.$subject.') in your pilot\'s message inbox on '.date('m/d/Y', time());
  157. Util::SendEmail($email, $sub, $message);
  158. }
  159. }
  160.  
  161. $this->set('message', '<div id="success">AIRMail Message Sent!</div>');
  162. }
  163.  
  164. //get sent messages
  165. public function sent() {
  166. if(!Auth::LoggedIn()) {
  167. $this->set('message', 'You must be logged in to access this feature!');
  168. $this->render('core_error.tpl');
  169. return;
  170. }
  171. $pid = Auth::$userinfo->pilotid;
  172. $this->set('mail', MailData::getsentmail($pid));
  173. $this->set('pilotcode', PilotData::GetPilotCode(Auth::$userinfo->code, Auth::$userinfo->pilotid));
  174. $this->menu();
  175. $this->show('mail/mail_sentitems.tpl');
  176. }
  177.  
  178. //settings for pilots
  179. public function settings() {
  180. if(!Auth::LoggedIn()) {
  181. $this->set('message', 'You must be logged in to access this feature!');
  182. $this->render('core_error.tpl');
  183. return;
  184. }
  185. $this->menu();
  186. $this->show('mail/mail_settings.tpl');
  187. }
  188.  
  189. //save new settings for pilot
  190. protected function save_settings() {
  191. if(!Auth::LoggedIn()) {
  192. $this->set('message', 'You must be logged in to access this feature!');
  193. $this->render('core_error.tpl');
  194. return;
  195. }
  196. if($this->post->email == '0')
  197. {MailData::remove_email_setting(Auth::$userinfo->pilotid);}
  198. else
  199. {
  200. if(MailData::send_email(Auth::$userinfo->pilotid) != TRUE)
  201. {MailData::set_email_setting(Auth::$userinfo->pilotid);}
  202. }
  203. $this->set('message', '<div id="success">Settings Saved</div>');
  204. $this->message();
  205. }
  206.  
  207. //delete a single message from view
  208. public function delete($mail_id) {
  209. if(!Auth::LoggedIn()) {
  210. $this->set('message', 'You must be logged in to access this feature!');
  211. $this->render('core_error.tpl');
  212. return;
  213. }
  214. MailData::deletemailitem($mail_id);
  215. $this->index();
  216. }
  217.  
  218. //delete all messages in particular folder view for pilot
  219. public function delete_all($folder) {
  220. if(!Auth::LoggedIn()) {
  221. $this->set('message', 'You must be logged in to access this feature!');
  222. $this->render('core_error.tpl');
  223. return;
  224. }
  225. $pid = Auth::$userinfo->pilotid;
  226. MailData::delete_inbox($pid, $folderid);
  227. $this->set('message', '<div id="success">All Inbox Messages Deleted</div>');
  228. $this->index();
  229. }
  230.  
  231. //delete single sent item from senders view
  232. public function sent_delete() {
  233. if(!Auth::LoggedIn()) {
  234. $this->set('message', 'You must be logged in to access this feature!');
  235. $this->render('core_error.tpl');
  236. return;
  237. }
  238. $mailid = $_GET['mailid'];
  239. MailData::deletesentmailitem($mailid);
  240. $this->sent();
  241. }
  242.  
  243. //delete all sent items from view
  244. public function delete_allsent() {
  245. if(!Auth::LoggedIn()) {
  246. $this->set('message', 'You must be logged in to access this feature!');
  247. $this->render('core_error.tpl');
  248. return;
  249. }
  250. $pid = Auth::$userinfo->pilotid;
  251. MailData::delete_sentbox($pid);
  252. $this->set('message', '<div id="success">All Sent Messages Deleted From View</div>');
  253. $this->sent();
  254. }
  255.  
  256. public function reply($thread_id) {
  257. if(!Auth::LoggedIn()) {
  258. $this->set('message', 'You must be logged in to access this feature!');
  259. $this->render('core_error.tpl');
  260. return;
  261. }
  262. $this->set('mail', MailData::getmailcontent($thread_id));
  263. $this->menu();
  264. $this->show('mail/mail_reply.tpl');
  265. }
  266.  
  267. public function checkmail() {
  268. if (!Auth::LoggedIn()) {
  269. }
  270. else {
  271. $item = MailData::checkformail();
  272. $items = $item->total;
  273. $this->set('items', $items);
  274. $this->show('mail/mail_check.tpl');
  275. }
  276. }
  277.  
  278. public function checkforfolders($pid) {
  279. $query = "SELECT *
  280. FROM airmail_folders
  281. WHERE pilot_id='$pid'";
  282.  
  283. return DB::query($query);
  284. }
  285.  
  286. //name new folder
  287. public function newfolder() {
  288. if(!Auth::LoggedIn()) {
  289. $this->set('message', 'You must be logged in to access this feature!');
  290. $this->render('core_error.tpl');
  291. return;
  292. }
  293. $this->menu();
  294. $this->show('mail/mail_newfolder.tpl');
  295. }
  296.  
  297. //save new folder
  298. protected function savefolder() {
  299. if(!Auth::LoggedIn()) {
  300. $this->set('message', 'You must be logged in to access this feature!');
  301. $this->render('core_error.tpl');
  302. return;
  303. }
  304. $folder_title = DB::escape($this->post->folder_title);
  305. MailData::savenewfolder($folder_title);
  306. header('Location: '.url('/Mail'));
  307. }
  308.  
  309. public function getfolder($id) {
  310. if(!Auth::LoggedIn()) {
  311. $this->set('message', 'You must be logged in to access this feature!');
  312. $this->render('core_error.tpl');
  313. return;
  314. }
  315. $this->set('folder', MailData::getfoldercontents($id));
  316. $this->set('mail', MailData::getfoldermail($id));
  317. $this->menu();
  318. $this->show('mail/mail_inbox.tpl');
  319. }
  320.  
  321. public function move_message($id) {
  322. if(!Auth::LoggedIn()) {
  323. $this->set('message', 'You must be logged in to access this feature!');
  324. $this->render('core_error.tpl');
  325. return;
  326. }
  327. $this->set('mail_id', $id);
  328. $this->set('folders', MailData::checkforfolders(Auth::$userinfo->pilotid));
  329. $this->menu();
  330. $this->show('mail/move_message');
  331. }
  332.  
  333. protected function move() {
  334. if(!Auth::LoggedIn()) {
  335. $this->set('message', 'You must be logged in to access this feature!');
  336. $this->render('core_error.tpl');
  337. return;
  338. }
  339. $folder = DB::escape($this->post->folder);
  340. $mail_id = DB::escape($this->post->mail_id);
  341. MailData::movemail($mail_id, $folder);
  342. header('Location: '.url('/Mail/getfolder/'.$folder));
  343. }
  344.  
  345. public function editfolder($id) {
  346. if(!Auth::LoggedIn()) {
  347. $this->set('message', 'You must be logged in to access this feature!');
  348. $this->render('core_error.tpl');
  349. return;
  350. }
  351. $this->set('folder', MailData::getfoldercontents($id));
  352. $this->menu();
  353. $this->show('mail/mail_editfolder.tpl');
  354. }
  355.  
  356. public function deletefolder() {
  357. if(!Auth::LoggedIn()) {
  358. $this->set('message', 'You must be logged in to access this feature!');
  359. $this->render('core_error.tpl');
  360. return;
  361. }
  362. $this->menu();
  363. $this->show('mail/mail_deletefolder.tpl');
  364. }
  365.  
  366. protected function confirm_delete_folder() {
  367. $folder_id = DB::escape($this->post->folder_id);
  368.  
  369. MailData::deletefolder($folder_id);
  370. $this->index();
  371. }
  372.  
  373. protected function confirm_edit_folder() {
  374. $folder_id = DB::escape($this->post->folder_id);
  375. $folder_title = DB::escape($this->post->folder_title);
  376. MailData::editfolder($folder_id, $folder_title);
  377. $this->index();
  378. }
  379.  
  380. public static function getallmail($pid, $limit = '5') {
  381. if(Auth::$userinfo->pilotid != $pid){
  382. throw new Exception("This mailbox does not belong to you. If you are accessing this via an Administration module, this feature is still in development");
  383. }
  384. $query = "SELECT *
  385. FROM `".TABLE_PREFIX."airmail`
  386. WHERE `who_to`='$pid'
  387. AND `deleted_state`='0'
  388. AND `receiver_folder`='0'
  389. ORDER BY `date` ASC
  390. LIMIT $limit";
  391.  
  392. $results = DB::get_results($query);
  393.  
  394. $code = DB::errno();
  395. if ($code != 0){
  396. $message = DB::error();
  397. throw new Exception($message, $code);
  398. }
  399.  
  400. return $results;
  401. }
  402.  
  403. public function GetProfileMail($limit){
  404. $pid = Auth::$userinfo->pilotid;
  405. $this->set('mail', MailData::getallmail($pid, $limit));
  406. $this->set('pilotcode', PilotData::GetPilotCode(Auth::$userinfo->code, Auth::$userinfo->pilotid));
  407. $this->show('mail/mail_profile.tpl');
  408. }
  409. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement