PageRenderTime 63ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/system/engine/class/public_engine.class.php

https://bitbucket.org/threetopia/thtech
PHP | 452 lines | 379 code | 21 blank | 52 comment | 56 complexity | 0acc1eb279c83af22f870e8ed254d37d MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. ###########################################################################################################################
  3. ## File name : public_engine.class.php
  4. ## Author : Tri Hartanto
  5. ## Site : trihartanto.com
  6. ## Framework : thtech ver.3
  7. ## CMS : triCMS ver.3
  8. ## Engine : thtech ver.3
  9. ## Engine type : Program type
  10. ## License : GPL
  11. ## Create Date : 28 September 2011
  12. ## Modified Date : 03 February 2013
  13. ## File Description : This file contains public engine class to process the framework and CMS system.
  14. ##
  15. ## This file is part of THTech Frameworks.
  16. ##
  17. ## THTech Frameworks is free software: you can redistribute it and/or modify
  18. ## it under the terms of the GNU General Public License as published by
  19. ## the Free Software Foundation, either version 3 of the License, or
  20. ## (at your option) any later version.
  21. ##
  22. ## THTech Frameworks is distributed in the hope that it will be useful,
  23. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. ## GNU General Public License for more details.
  26. ##
  27. ## You should have received a copy of the GNU General Public License
  28. ## along with THTech Frameworks. If not, see <http://www.gnu.org/licenses/>.
  29. ##
  30. ###########################################################################################################################
  31. class System_Public_Engine_Class
  32. {
  33. public function __call($name,$arguments)
  34. {
  35. return $this->loadSysPubEngineLibrary(array('libraryName'=>$name,'libraryArguments'=>$arguments,'ismethod'=>true));
  36. }
  37. public function __get($var=NULL)
  38. {
  39. return $this->loadSysPubEngineLibrary(array('libraryName'=>$var,'ismethod'=>false));
  40. }
  41. private function loadSysPubEngineLibrary($data=NULL)
  42. {
  43. $libraryName = explode('_',$data['libraryName'],2);
  44. $libraryFile = dirname(__FILE__).'/../syspubengine_library/'.$libraryName[0].'.class.php';
  45. $libraryClass = ucfirst($libraryName[0]).'_SysPubEngine_Library';
  46. if(!isset($this->$libraryClass) and file_exists($libraryFile))
  47. {
  48. include_once($libraryFile);
  49. if(class_exists($libraryClass))
  50. {
  51. $this->$libraryClass = new $libraryClass();
  52. }
  53. }
  54. if($data['ismethod']===true and method_exists($this->$libraryClass,$libraryName[1]))
  55. {
  56. return call_user_func_array(array($this->$libraryClass,$libraryName[1]),$data['libraryArguments']);
  57. }
  58. else if($data['ismethod']===false and isset($this->$libraryClass->$libraryName[1]))
  59. {
  60. return $this->$libraryClass->$libraryName[1];
  61. }
  62. return false;
  63. }
  64. public function addhtmlhead($data=NULL)
  65. {
  66. $GLOBALS['_SysEngine']->addhtmlhead($data);
  67. }
  68. public function createanchor($data=NULL)
  69. {
  70. $JSONData = (!empty($data['attribute']) and !is_array($data['attribute']))?json_decode($data['attribute'],true):NULL;
  71. $AnchorAttribute = (is_array($JSONData))?$JSONData:((!empty($data['attribute']))?$data['attribute']:NULL);
  72. $attribute = '';
  73. if(!empty($AnchorAttribute) and is_array($AnchorAttribute))
  74. {
  75. $AnchorAttribute['title'] = (isset($AnchorAttribute['title']))?$AnchorAttribute['title']:$data['title'];
  76. foreach($AnchorAttribute as $AnchorAttKey=>$AnchorAttVal)
  77. {
  78. if(strtolower($AnchorAttKey)!='href')
  79. {
  80. $attribute .= ' '.$AnchorAttKey.'="'.$AnchorAttVal.'" ';
  81. }
  82. }
  83. }
  84. else
  85. {
  86. $attribute .= ' '.$AnchorAttribute.' ';
  87. }
  88. $AnchorURL = (!empty($data['URLData']))?$this->createurl(array('URLData'=>$data['URLData'])):NULL;
  89. $html = '';
  90. $html .= '<a '.((!empty($AnchorURL))?'href="'.$AnchorURL.'"':'').' '.$attribute.'>';
  91. $html .= ' '.$data['title'].'';
  92. $html .= '</a>';
  93. return $html;
  94. }
  95. public function redirect($data=NULL)
  96. {
  97. $html = '';
  98. $location = $this->createurl($data);
  99. if(!empty($location))
  100. {
  101. $html = header('Location: '.$location.'');
  102. }
  103. return $html;
  104. }
  105. public function createurl($data=NULL)
  106. {
  107. $URLData = (!empty($data['URLData']))?$data['URLData']:((isset($data['URLApp']) or isset($data['URLLink']) or isset($data['URLString']))?$data:NULL);
  108. #################################################################################
  109. $_URLDecode = (empty($data['_URLDecode']))?$GLOBALS['_URLDecode']:$data['_URLDecode'];
  110. ################# Get _AppData used for program location ################
  111. $_AppData = (empty($data['_AppData']))?$GLOBALS['_AppData']:$data['_AppData'];
  112. #################################################################################
  113. $URLApp = (isset($URLData['URLApp']))?$URLData['URLApp']:((!empty($_URLDecode['URLApp']))?$_URLDecode['URLApp']:((!empty($_AppData[0]['uprgm_name']))?$_AppData[0]['uprgm_name']:NULL));
  114. $URLLink = (isset($URLData['URLLink']))?$URLData['URLLink']:((!empty($_URLDecode['URLLink']))?$_URLDecode['URLLink']:((!empty($_NavData[0]['nav_name']))?$_NavData[0]['nav_name']:NULL));
  115. $URLExtPath = (isset($URLData['URLExtPath']))?$URLData['URLExtPath']:((!empty($_URLDecode['URLExtPath']))?$_URLDecode['URLExtPath']:((!empty($_NavData[0]['nav_extpath']))?$_NavData[0]['nav_extpath']:NULL));
  116. $URLString = (isset($URLData['URLString']))?$URLData['URLString']:((!empty($_URLDecode['URLString']))?$_URLDecode['URLString']:((!empty($_NavData[0]['nav_string']))?$_NavData[0]['nav_string']:NULL));
  117. $URLIndex = (isset($URLData['URLIndex']))?$URLData['URLIndex']:((!empty($_URLDecode['URLIndex']))?$_URLDecode['URLIndex']:((!empty($_AppData[0]['type_index']))?$_AppData[0]['type_index']:NULL));
  118. $html = '';
  119. $html = HTTP_ROOT_DIR;
  120. $html .= ((FRIENDLYURLINDEX===true or !empty($URLData['URLIndex'])) and (!empty($URLIndex)))?'/'.$URLIndex:NULL;
  121. $html .= ($URLApp!=NULL)?'/'.$URLApp:NULL;
  122. $html .= ($URLLink!=NULL)?'/'.$URLLink:NULL;
  123. if(!empty($URLExtPath))
  124. {
  125. $URLExtPath = (!is_array($URLExtPath))?json_decode($URLExtPath,true):$URLExtPath;
  126. foreach($URLExtPath as $val)
  127. {
  128. $html .= (!empty($val))?'/'.$val:'';
  129. }
  130. }
  131. if(!empty($URLString))
  132. {
  133. $loop = 0;
  134. $URLString = (!is_array($URLString))?json_decode($URLString,true):$URLString;
  135. foreach($URLString as $key=>$val)
  136. {
  137. $loop++;
  138. $html .= (!empty($val))?((($loop==1)?'?':'&').$key.'='.$val):'';
  139. }
  140. }
  141. return $html;
  142. }
  143. public function syssession($data=NULL)
  144. {
  145. @session_start();
  146. #################################################################################
  147. $_AppData = (!empty($GLOBALS['_AppData']))?$GLOBALS['_AppData']:((!empty($data['_AppData']))?$data['_AppData']:array());unset($data['_AppData']);
  148. #################################################################################
  149. $action = (!empty($data['action']))?$data['action']:'get';unset($data['action']);
  150. $timeout = (!empty($data['timeout']))?$data['timeout']:NULL;unset($data['timeout']);
  151. $syslogged = $syssession = array();
  152. if(!empty($data))
  153. {
  154. foreach($data as $key=>$val)
  155. {
  156. if($key === 'syslogged')
  157. {
  158. $syslogged = $this->setsyslogged(array('_AppData'=>$_AppData,'action'=>$action,'syslogged'=>$val));
  159. }
  160. else
  161. {
  162. $syssession = $this->setsyssession(array('_AppData'=>$_AppData,'action'=>$action,'key'=>$key,'val'=>$val));
  163. }
  164. }
  165. }
  166. $syssession = (!empty($syslogged) and !empty($syssession))?array_merge_recursive($syslogged,$syssession):((!empty($syslogged))?$syslogged:$syssession);
  167. return $syssession;
  168. }
  169. private function setsyssession($data=NULL)
  170. {
  171. #################################################################################
  172. $_AppData = $data['_AppData'];unset($data['_AppData']);
  173. #################################################################################
  174. $SessionData = false;
  175. if(!empty($data))
  176. {
  177. //$syssession = (!empty($data['val']))?$data['val']:$_SESSION[$data['key']];
  178. $syssession = (isset($_SESSION[$data['key']]))?$_SESSION[$data['key']]:$data['val'];
  179. $data['syssession'] = (!empty($data['val']))?$data['val']:$syssession;
  180. if($data['action']==='set')
  181. {
  182. if(!empty($data['syssession']))
  183. {
  184. foreach($data['syssession'] as $key=>$val)
  185. {
  186. //if(!in_array($val,$syssession))
  187. //{
  188. $_SESSION[$data['key']][$key] = $val;
  189. //}
  190. }
  191. }
  192. }
  193. else if($data['action']==='get')
  194. {
  195. if(!empty($data['syssession']))
  196. {
  197. foreach($data['syssession'] as $key=>$val)
  198. {
  199. if(isset($_SESSION[$data['key']][$val]))
  200. {
  201. $SessionData[$data['key']][$val] = $_SESSION[$data['key']][$val];
  202. }
  203. else if(isset($_SESSION[$data['key']]) and in_array($val,$syssession))
  204. {
  205. $SessionData[$data['key']][$key] = $_SESSION[$data['key']][$key];
  206. }
  207. }
  208. }
  209. }
  210. else if($data['action']==='unset')
  211. {
  212. if(isset($_SESSION[$data['key']]) and !empty($data['syssession']))
  213. {
  214. foreach($data['syssession'] as $key=>$val)
  215. {
  216. if(isset($_SESSION[$data['key']][$val]))
  217. {
  218. unset($_SESSION[$data['key']][$val]);
  219. }
  220. else if(in_array($val,$syssession))
  221. {
  222. unset($_SESSION[$data['key']][$key]);
  223. }
  224. }
  225. }
  226. else if(isset($_SESSION[$data['key']]))
  227. {
  228. unset($_SESSION[$data['key']]);
  229. }
  230. }
  231. }
  232. return $SessionData;
  233. }
  234. private function setsyslogged($data=NULL)
  235. {
  236. #################################################################################
  237. $_AppData = $data['_AppData'];unset($data['_AppData']);
  238. #################################################################################
  239. $SessionData = array();
  240. if(!empty($data) and !empty($_AppData))
  241. {
  242. $syslogged = array('iprgm','uprgm','global');
  243. $data['syslogged'] = (!empty($data['syslogged']))?$data['syslogged']:$syslogged;
  244. if($data['action']=='set')
  245. {
  246. foreach($data['syslogged'] as $key=>$val)
  247. {
  248. if(in_array($val,$syslogged))
  249. {
  250. $keyset = ($val!='global')?$_AppData[0][$val.'_name'].'_'.$val.'logged':'globallogged';
  251. $_SESSION['_SysLogged'][$keyset] = true;
  252. }
  253. }
  254. }
  255. else if($data['action']=='get')
  256. {
  257. foreach($data['syslogged'] as $key=>$val)
  258. {
  259. if(in_array($val,$syslogged))
  260. {
  261. $keyget = ($val!='global')?$_AppData[0][$val.'_name'].'_'.$val.'logged':'globallogged';
  262. if(isset($_SESSION['_SysLogged'][$keyget]))
  263. {
  264. $SessionData[$keyget] = $_SESSION['_SysLogged'][$keyget];
  265. }
  266. else
  267. {
  268. $SessionData[$keyget] = false;
  269. }
  270. }
  271. }
  272. }
  273. else if($data['action']=='unset')
  274. {
  275. foreach($data['syslogged'] as $key=>$val)
  276. {
  277. if(in_array($val,$syslogged))
  278. {
  279. $keyget = ($val!='global')?$_AppData[0][$val.'_name'].'_'.$val.'logged':'globallogged';
  280. if(isset($_SESSION['_SysLogged'][$keyget]))
  281. {
  282. unset($_SESSION['_SysLogged'][$keyget]);
  283. }
  284. }
  285. }
  286. }
  287. }
  288. return $SessionData;
  289. }
  290. public function upload($data=NULL)
  291. {
  292. $UploadData = $data['UploadData'];
  293. $status = array();
  294. $NewFileName = '';
  295. if(!empty($_FILES) and is_array($_FILES))
  296. {
  297. foreach($_FILES as $key=>$val)
  298. {
  299. $UploadData['overwrite'][$key] = false;
  300. $UploadData['overwrite'] = false;
  301. $CountFiles[$key] = count($val['name']);
  302. if(is_array($val['name']) and !empty($_FILES[$key]["tmp_name"]))
  303. {
  304. for($a=0;$a<$CountFiles[$key];$a++)
  305. {
  306. $NewFileName[$key][$a] = (((!empty($UploadData['filename'][$a]) and is_array($UploadData['filename'])) or (!empty($UploadData['filename']) and !is_array($UploadData['filename'])) or (!empty($UploadData['filename'][$key][$a]) and is_array($UploadData['filename'][$key])) or (!empty($UploadData['filename'][$key]) and !is_array($UploadData['filename'][$key])))?((!empty($UploadData['filename'][$key][$a]) and is_array($UploadData['filename'][$key]))?$UploadData['filename'][$key][$a]:((!empty($UploadData['filename'][$key]) and !is_array($UploadData['filename'][$key]))?$UploadData['filename'][$key]:((is_array($UploadData['filename']))?$UploadData['filename'][$a]:$UploadData['filename']))):$_FILES[$key]["name"][$a]);
  307. $NewFilePath[$key][$a] = (((!empty($UploadData['filepath'][$a]) and is_array($UploadData['filepath'])) or (!empty($UploadData['filepath']) and !is_array($UploadData['filepath'])) or (!empty($UploadData['filepath'][$key][$a]) and is_array($UploadData['filepath'][$key])) or (!empty($UploadData['filepath'][$key]) and !is_array($UploadData['filepath'][$key])))?((!empty($UploadData['filepath'][$key][$a]) and is_array($UploadData['filepath'][$key]))?$UploadData['filepath'][$key][$a]:((!empty($UploadData['filepath'][$key]) and !is_array($UploadData['filepath'][$key]))?$UploadData['filepath'][$key]:((is_array($UploadData['filepath']))?$UploadData['filepath'][$a]:$UploadData['filepath']))):SYSTEM_TEMPORARY_DIR.'/');
  308. $NewFileFullPath[$key][$a] = (((!empty($UploadData['filefullpath'][$a]) and is_array($UploadData['filefullpath'])) or (!empty($UploadData['filefullpath']) and !is_array($UploadData['filefullpath'])) or (!empty($UploadData['filefullpath'][$key][$a]) and is_array($UploadData['filefullpath'][$key])) or (!empty($UploadData['filefullpath'][$key]) and !is_array($UploadData['filefullpath'][$key])))?((!empty($UploadData['filefullpath'][$key][$a]) and is_array($UploadData['filefullpath'][$key]))?$UploadData['filefullpath'][$key][$a]:((!empty($UploadData['filefullpath'][$key]) and !is_array($UploadData['filefullpath'][$key]))?$UploadData['filefullpath'][$key]:((is_array($UploadData['filefullpath']))?$UploadData['filefullpath'][$a]:$UploadData['filefullpath']))):$NewFilePath[$key][$a].$NewFileName[$key][$a]);
  309. if(((((!empty($UploadData['overwrite'][$key][$a]))?$UploadData['overwrite'][$key][$a]:((!empty($UploadData['overwrite'][$key]))?$UploadData['overwrite'][$key]:$UploadData['overwrite']))==true)?true:!file_exists($NewFileFullPath[$key][$a])) and ((!empty($UploadData['type'][$key]) and is_array($UploadData['type'][$key][$a]))?in_array($_FILES[$key]["type"][$a],$UploadData['type'][$key][$a]):((!empty($UploadData['type'][$key]) and is_array($UploadData['type'][$key]))?in_array($_FILES[$key]["type"][$a],$UploadData['type'][$key]):((!empty($UploadData['type']) and is_array($UploadData['type']))?in_array($_FILES[$key]["type"][$a],$UploadData['type']):true))) and ((!empty($UploadData['size'][$key][$a]))?($_FILES[$key]["size"][$a] <= $UploadData['size'][$key][$a]):((!empty($UploadData['size'][$key]))?($_FILES[$key]["size"][$a] <= $UploadData['size'][$key]):((!empty($UploadData['size']))?($_FILES[$key]["size"][$a] <= $UploadData['size']):true))) and !empty($_FILES[$key]["tmp_name"][$a]))
  310. {
  311. //echo $a.').'.$_FILES[$key]["tmp_name"][$a].'<=>'.$NewFileFullPath[$a].'<br>';
  312. move_uploaded_file($_FILES[$key]["tmp_name"][$a],$NewFileFullPath[$a]);
  313. $status[$key][$a] = true;
  314. }
  315. else
  316. {
  317. $status[$key][$a] = false;
  318. }
  319. //unset($FileName,$FilePath,$FullPath);
  320. }
  321. }
  322. else if(!is_array($val['name']) and !empty($_FILES[$key]["tmp_name"]))
  323. {
  324. $NewFileName[$key] = ((!empty($UploadData['filename'][$key]) and !is_array($UploadData['filename'][$key]))?$UploadData['filename'][$key]:((!empty($UploadData['filename']) and !is_array($UploadData['filename']))?$UploadData['filename']:((!empty($_POST['filename']))?$_POST['filename']:$_FILES[$key]["name"])));
  325. $NewFilePath[$key] = ((!empty($UploadData['filepath'][$key]) and !is_array($UploadData['filepath'][$key]))?$UploadData['filepath'][$key]:((!empty($UploadData['filepath']) and !is_array($UploadData['filepath']))?$UploadData['filepath']:((!empty($_POST['filepath']))?$_POST['filepath']:SYSTEM_TEMPORARY_DIR.'/')));
  326. $NewFileFullPath[$key] = ((!empty($UploadData['filefullpath'][$key]) and !is_array($UploadData['filefullpath'][$key]))?$UploadData['filefullpath'][$key]:((!empty($UploadData['filefullpath']) and !is_array($UploadData['filefullpath']))?$UploadData['filefullpath']:((!empty($_POST['filefullpath']))?$_POST['filefullpath']:$NewFilePath[$key].$NewFileName[$key])));
  327. if(((((!empty($UploadData['overwrite'][$key]))?$UploadData['overwrite'][$key]:$UploadData['overwrite'])==true)?true:!file_exists($NewFileFullPath[$key])) and ((!empty($UploadData['type'][$key]) and is_array($UploadData['type'][$key]))?in_array($_FILES[$key]["type"],$UploadData['type'][$key]):((!empty($UploadData['type']) and is_array($UploadData['type']))?in_array($_FILES[$key]["type"],$UploadData['type']):true)) and (!empty($UploadData['size'])?($_FILES[$key]["size"] <= $UploadData['size']):true) and !empty($_FILES[$key]["tmp_name"]))
  328. {
  329. //echo $key.').'.$_FILES[$key]["tmp_name"].'<=>'.$NewFileFullPath.'<br>';
  330. move_uploaded_file($_FILES[$key]["tmp_name"],$NewFileFullPath);
  331. $status[$key] = true;
  332. }
  333. else
  334. {
  335. $status[$key] = false;
  336. }
  337. }
  338. }
  339. }
  340. $DataArray = array('FileName'=>((!empty($NewFileName))?$NewFileName:NULL),'FilePath'=>((!empty($NewFilePath))?$NewFilePath:NULL),'FileFullPath'=>((!empty($NewFileFullPath))?$NewFileFullPath:NULL),'FileCount'=>((!empty($CountFiles))?$CountFiles:NULL),'status'=>$status);
  341. return $DataArray;
  342. }
  343. public function scandirectory($data=NULL)
  344. {
  345. $ScanMode = (isset($data['scanmode']))?$data['scanmode']:NULL;
  346. $ScanDirResult = array();
  347. $ScanDir = scandir($data['directory']);
  348. $DefaultExclude = array('.','..');
  349. $Exclude = (!empty($Exclude) and is_array($data['exclude']))?$data['exclude']:array();
  350. $Exclude = array_merge($DefaultExclude,$Exclude);
  351. if($ScanMode != 'plain')
  352. {
  353. if(!empty($ScanDir) and is_array($ScanDir))
  354. {
  355. foreach($ScanDir as $key=>$val)
  356. {
  357. if(!in_array($val,$Exclude))
  358. {
  359. $ScanDirResult[] = $val;
  360. }
  361. }
  362. }
  363. }
  364. else if($ScanMode == 'plain')
  365. {
  366. $ScanDirResult = $ScanDir;
  367. }
  368. return $ScanDirResult;
  369. }
  370. public function sendmail($data=NULL)
  371. {
  372. $_LibPHPMailer = $GLOBALS['_LibPHPMailer'];
  373. $_ProgramConfig = (isset($GLOBALS['_SysEngine']->_CurProgramConfig['email']) and !empty($GLOBALS['_SysEngine']->_CurProgramConfig['email']))?$GLOBALS['_SysEngine']->_CurProgramConfig['email']:NULL;
  374. //print_r($_ProgramConfig);
  375. $mail = $_LibPHPMailer;
  376. $body = ((!empty($data['emailBody']))?$data['emailBody']:((!empty($_ProgramConfig['emailBody']))?$_ProgramConfig['emailBody']:'Email'));
  377. $mail->IsSMTP(); // telling the class to use SMTP
  378. $mail->Host = ((!empty($data['emailHost']))?$data['emailHost']:((!empty($_ProgramConfig['emailHost']))?$_ProgramConfig['emailHost']:EMAIL_HOST)); // SMTP server
  379. //$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
  380. // 1 = errors and messages
  381. // 2 = messages only
  382. $mail->SMTPAuth = true; // enable SMTP authentication
  383. $mail->Port = ((!empty($data['emailPort']))?$data['emailPort']:((!empty($_ProgramConfig['emailPort']))?$_ProgramConfig['emailPort']:EMAIL_PORT)); // set the SMTP port for the GMAIL server
  384. $mail->Username = ((!empty($data['emailUsername']))?$data['emailUsername']:((!empty($_ProgramConfig['emailUsername']))?$_ProgramConfig['emailUsername']:EMAIL_USERNAME)); // SMTP account username
  385. $mail->Password = ((!empty($data['emailPassword']))?$data['emailPassword']:((!empty($_ProgramConfig['emailPassword']))?$_ProgramConfig['emailPassword']:EMAIL_PASSWORD)); // SMTP account password
  386. $CheckEmail = explode('@',((!empty($data['emailSentTo']['address']))?$data['emailSentTo']['address']:((!empty($_ProgramConfig['emailSentTo']['address']))?$_ProgramConfig['emailSentTo']['address']:'')));
  387. if(!empty($CheckEmail[1]))
  388. {
  389. $CheckEmailDomain = explode('.',$CheckEmail[1]);
  390. }
  391. $mail->SetFrom(((!empty($data['emailSentFrom']['address']))?$data['emailSentFrom']['address']:((!empty($_ProgramConfig['emailSentFrom']['address']))?$_ProgramConfig['emailSentFrom']['address']:EMAIL_ADDRESS)), ((!empty($data['emailSentFrom']['title']))?$data['emailSentFrom']['title']:((!empty($_ProgramConfig['emailSentFrom']['title']))?$_ProgramConfig['emailSentFrom']['title']:DEFAULT_EMAIL_TITLE)));
  392. $mail->AddReplyTo(((!empty($data['emailReplyTo']['address']))?$data['emailReplyTo']['address']:((!empty($_ProgramConfig['emailReplyTo']['address']))?$_ProgramConfig['emailReplyTo']['address']:EMAIL_ADDRESS)),((!empty($data['emailReplyTo']['title']))?$data['emailReplyTo']['title']:((!empty($_ProgramConfig['emailReplyTo']['title']))?$_ProgramConfig['emailReplyTo']['title']:DEFAULT_EMAIL_TITLE)));
  393. $mail->Subject = (!empty($data['emailSubject'])?$data['emailSubject']:((!empty($_ProgramConfig['emailSubject']))?$_ProgramConfig['emailSubject']:NULL));
  394. //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
  395. $mail->MsgHTML($body);
  396. //echo (!empty($data['emailSentTo']['address']))?$data['emailSentTo']['address']:((!empty($_ProgramConfig['emailSentTo']['address']))?$_ProgramConfig['emailSentTo']['address']:NULL);
  397. $mail->AddAddress(((!empty($data['emailSentTo']['address']))?$data['emailSentTo']['address']:((!empty($_ProgramConfig['emailSentTo']['address']))?$_ProgramConfig['emailSentTo']['address']:NULL)),((!empty($data['emailSentTo']['title']))?$data['emailSentTo']['title']:((!empty($_ProgramConfig['emailSentTo']['title']))?$_ProgramConfig['emailSentTo']['title']:NULL)));
  398. $mail->AddBCC(((!empty($data['emailBCC']['address']))?$data['emailBCC']['address']:((!empty($_ProgramConfig['emailBCC']['address']))?$_ProgramConfig['emailBCC']['address']:NULL)),((!empty($data['emailBCC']['title']))?$data['emailBCC']['title']:((!empty($_ProgramConfig['emailBCC']['title']))?$_ProgramConfig['emailBCC']['title']:NULL)));
  399. if(!$mail->Send() and (empty($CheckEmail[1]) and empty($CheckEmailDomain[1])))
  400. {
  401. $error = "Mailer Error: ".$mail->ErrorInfo;
  402. $state = false;
  403. }
  404. else
  405. {
  406. $error = false;
  407. $state = true;
  408. }
  409. return array('emailstatus'=>$state,'error'=>$error);
  410. }
  411. public function timezoneconverter($data=NULL)
  412. {
  413. $defaulttimezone = date('e',time());
  414. $fromzone = (isset($data['from']))?$data['from']:$defaulttimezone;
  415. $date = new DateTime($data['datetime'],new DateTimeZone($fromzone));
  416. date_default_timezone_set($fromzone);//set from time zone
  417. $fromdate = $date->format((!empty($fromdateformat))?$fromdateformat:(($dateformat)?$dateformat:'Y-m-d'));
  418. $fromtime = $date->format((!empty($fromtimeformat))?$fromtimeformat:(($timeformat)?$timeformat:'H:i:s'));
  419. $fromunixtime = mktime($date->format('H'),$date->format('i'),$date->format('s'),$date->format('m'),$date->format('d'),$date->format('Y'));
  420. $tozone = (!empty($to))?$to:$defaulttimezone;
  421. date_default_timezone_set($tozone);//set to timezone
  422. $date->setTimeZone(new DateTimeZone($tozone));
  423. $todate = $date->format((!empty($todateformat))?$todateformat:(($dateformat)?$dateformat:'Y-m-d'));
  424. $totime = $date->format((!empty($totimeformat))?$totimeformat:(($timeformat)?$timeformat:'H:i:s'));
  425. $tounixtime = mktime($date->format('H'),$date->format('i'),$date->format('s'),$date->format('m'),$date->format('d'),$date->format('Y'));
  426. //echo $date->format('d-m-Y H:i:s P e');
  427. date_default_timezone_set($defaulttimezone);//backit again to default system timezone
  428. return array('fromzone'=>$fromzone,'fromdate'=>$fromdate,'fromtime'=>$fromtime,'fromunixtime'=>$fromunixtime,'tozone'=>$tozone,'todate'=>$todate,'totime'=>$totime,'tounixtime'=>$fromunixtime);
  429. }
  430. }
  431. ?>