PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/application/controllers/baseController.php

https://bitbucket.org/mageecprojects/portail3g
PHP | 692 lines | 418 code | 152 blank | 122 comment | 31 complexity | ed91b87d4009453f191484c18d5128ff MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * @todo -c Implement . remettre le https sur le domaine avant d emettre en production
  4. */
  5. class baseController{
  6. /**
  7. * Constuctor
  8. * priv
  9. */
  10. protected $database;
  11. protected $vue;
  12. protected $current_user;
  13. protected $generaltitle;
  14. protected $abregedtitle;
  15. protected $logstatus;
  16. protected $domain;
  17. protected $MES_SUCESS;
  18. protected $MES_ERROR;
  19. protected $MES_WARNING;
  20. protected $MES_INFOS;
  21. protected $previous_url;
  22. protected $login_url;
  23. protected $inscription_url;
  24. protected $logout_url;
  25. protected $forget_url;
  26. protected $offres_url;
  27. protected $dashbord_url;
  28. protected $device_list;
  29. protected $device_list_soap;
  30. protected $send_forfait_url;
  31. protected $stop_forfait_url;
  32. protected $change_password_url;
  33. protected $recharge_url;
  34. protected $contact_url;
  35. protected $pay_as_go_url;
  36. protected $contact_clientele_moov;
  37. // protected $contact_clientele_moov;
  38. function __construct(){
  39. // session_start();
  40. // print_r($_SESSION);
  41. $this->domain="http://".$_SERVER["HTTP_HOST"].dirname($_SERVER['PHP_SELF'])."/";
  42. //$this->domain="https://".$_SERVER["HTTP_HOST"].dirname($_SERVER['PHP_SELF'])."/";
  43. // require_once('config.php');
  44. $this->contact_clientele_moov="selfcare3g@moov.com";
  45. $this->generaltitle="Moov Portail 3G|Achetez vos forfaits 3g en ligne et suivez votre consommation";
  46. $this->device_list=array(
  47. "0"=>"SMARTPHONE",
  48. "1"=>"CLE USB",
  49. "2"=>"TABLETTE",
  50. "3"=>"BOX"
  51. );
  52. $this->device_list_soap=array(
  53. "0"=>"SMARTPHONE",
  54. "1"=>"CLE",
  55. "2"=>"TABLETTE",
  56. "3"=>"BOX"
  57. );
  58. $this->MES_SUCESS="success";
  59. $this->MES_ERROR="error";
  60. $this->MES_WARNING="warning";
  61. $this->MES_INFOS="info";
  62. $this->login_url="connexion/";
  63. // $this->login_url="?ctrl=inscription&action=connexion";
  64. // $this->inscription_url="?ctrl=inscription&action=inscription";
  65. $this->inscription_url="getpassword/";
  66. $this->pay_as_go_url="account/payg/";
  67. $this->logout_url="?ctrl=operations&action=logout";
  68. $this->forget_url="account/password/reinit/";
  69. // $this->forget_url="?ctrl=inscription&action=forgetpass";
  70. // $this->offres_url="?ctrl=operations&action=forfaits";
  71. $this->offres_url="account/packs/";
  72. $this->dashbord_url="account/";
  73. //$this->send_forfait_url="?ctrl=operations&action=offrir_forfaits";
  74. $this->send_forfait_url="account/send/";
  75. $this->stop_forfait_url="?ctrl=operations&action=stop";
  76. // $this->change_password_url="?ctrl=operations&action=change_password";
  77. $this->change_password_url="account/password/change/";
  78. $this->recharge_url="recharge/";
  79. $this->contact_url="account/contact/";
  80. require_once('config.php');
  81. $this->database=new PDOConfig('mysql',$DB_HOST,$DB_DATABASE,$DB_USER,$DB_PASS);
  82. $this->database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  83. mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
  84. if($this->isMobileDevice()){
  85. // echo "mobile";
  86. $this->vue=new Template('application/views/mobile');
  87. }else{
  88. $this->vue=new Template('application/views/pc/');
  89. }
  90. // $this->vue=new Template('application/views/');
  91. $this->vue->assign_var("PAGE_TITLE",$this->generaltitle );
  92. $_SESSION["previous"]=$this->dashbord_url;
  93. $this->assignConnInfos();
  94. }
  95. //--------------------------------------
  96. function getEmail(){
  97. $numero=Tools::getsession("num_conn");
  98. $search="select email from 3g_inscrits where numero='$numero'";
  99. $reponse=$this->database->executeOne($search);
  100. if(empty($reponse)){
  101. return null;
  102. }else{
  103. return $reponse["email"];
  104. }
  105. // return "ok";
  106. }
  107. //-------------------------------
  108. function remove_inscrit($numero){
  109. $sql="delete from 3g_inscrits where numero='$numero'";
  110. $this->database->execCustom($sql);
  111. }
  112. //-------------------------------
  113. function add_inscrit($numero,$password,$email="",$nom="",$prenom="",$equipement=""){
  114. $insert_inscrit="insert into 3g_inscrits values (null,'$numero','$password','$email','$nom','$prenom','$equipement')";
  115. $this->database->execCustom($insert_inscrit);
  116. }
  117. //----------------------------
  118. public function filterForfaits($liste_offres,$equipement){
  119. $res=array();
  120. $list_prix=array();
  121. $offre=new Moov3GOffre();
  122. $liste_good_forfaits=array();
  123. /* $liste_good_forfaits["0"]=array("jour","epiq","semaine","plus","extra");
  124. $liste_good_forfaits["2"]=array("premium","maxi","extra");
  125. $liste_good_forfaits["3"]=array("premium","maxi","extra");
  126. $liste_good_forfaits["1"]=array("maxi","semaine","plus","extra");*/
  127. /* $liste_good_forfaits["0"]="/jour|epiq|semaine|plus|extra/i";
  128. $liste_good_forfaits["1"]="/maxi|semaine|plus|extra/i";
  129. $liste_good_forfaits["2"]="/premium|maxi|extra/i";
  130. $liste_good_forfaits["3"]="/premium|maxi|extra/i";*/
  131. // $pattern=$liste_good_forfaits[$equipement];
  132. foreach($liste_offres as $offre){
  133. $nom_forfait=$offre->Nom;
  134. // if(preg_match($pattern,$nom_forfait )){
  135. $res[]=$offre;
  136. $list_prix[]=intval($offre->Montant);
  137. // }
  138. }
  139. //print_r($list_prix);
  140. array_multisort($list_prix, SORT_ASC,SORT_NUMERIC,$res);
  141. return $res;
  142. }
  143. //-------------------------------
  144. public function getInfosMembre($conn=null){
  145. $infos=new Moov3GResponseInfoMembre();
  146. $client=new Moov3GSoapWebsiteClient();
  147. if($conn==null){
  148. $conn=Tools::getsession("id_conn");
  149. }
  150. $infos=$client->InfoMembre($conn);
  151. if(Tools::getsession("num_conn")=="42689986"){
  152. // var_dump($infos);
  153. }
  154. if($infos->Succes){
  155. $nom=($infos->Nom=="") ? "ABONNE":$infos->Nom;
  156. $prenoms=($infos->Prenoms=="")? "SANS NOM":$infos->Prenoms;
  157. if($nom=="ABONNE"){
  158. $fullname="";
  159. }else{
  160. $fullname=$nom." ".$prenoms;
  161. }
  162. $equipement_soap=($infos->Equipement=="")? "SMARTPHONE":$infos->Equipement;
  163. $_SESSION["realname"]=$infos->Nom;
  164. $_SESSION["realprenom"]=$infos->Prenoms;
  165. return array("success"=>true,"nom"=>$nom,"prenom"=>$prenoms,"equipement"=>$equipement_soap,"email"=>$infos->Email,"fullname"=>$fullname,"realnom"=>$infos->Nom,"realprenom"=>$infos->Prenoms);
  166. }else{
  167. return array("success"=>false,"error"=>utf8_encode($infos->MessageErreur).".");
  168. }
  169. }
  170. //-------------------------------
  171. //cette fonction permet d attribuer automatiquement dans la vue les liens de connexion,
  172. //deconnexion,infos du numero connecté a tous les endrois qui en ont besoin
  173. public function assignConnInfos(){
  174. $connected=$this->status_connexion();
  175. $equipement=Tools::getsession("equipement");
  176. if($connected) {
  177. $infos=$this->getInfosMembre();
  178. }else{
  179. $infos=array();
  180. }
  181. $this->vue->assign_var("log_num",Tools::getsession("num_conn"));
  182. $this->vue->assign_var("log_fullname",ucwords($infos["fullname"]));
  183. $this->vue->assign_var("GL_INSCRIPTION",$this->inscription_url);
  184. $this->vue->assign_var("GL_CONNEXION",$this->login_url);
  185. $this->vue->assign_var("GL_DECONNEXION",$this->logout_url);
  186. $this->vue->assign_var("GL_FORGETPASS",$this->forget_url);
  187. $this->vue->assign_var("GL_FORFAITS",$this->offres_url);
  188. $this->vue->assign_var("GL_DASHBOARD",$this->dashbord_url);
  189. $this->vue->assign_var("GL_SEND_FORFAIT",$this->send_forfait_url);
  190. $this->vue->assign_var("CONSO_RATIO","0");
  191. // $this->vue->assign_var("device",$this->device_list[$equipement]);
  192. $this->vue->assign_var("device",$equipement);
  193. $this->vue->assign_var("GL_STOP_FORFAIT",$this->stop_forfait_url);
  194. $this->vue->assign_var("GL_CHANGE_PASS",$this->change_password_url);
  195. $this->vue->assign_var("DOMAIN",$this->domain);
  196. $this->vue->assign_var("GL_RECHARGE",$this->recharge_url);
  197. $this->vue->assign_var("user_nom",$infos["nom"]);
  198. $this->vue->assign_var("user_prenoms",$infos["prenom"]);
  199. $this->vue->assign_var("user_email",strtolower($infos["email"]));
  200. $this->vue->assign_var("GL_RECHARGE",$this->recharge_url);
  201. $this->vue->assign_var("GL_CONTACT",$this->contact_url);
  202. $this->vue->assign_var("GL_PAYG",$this->pay_as_go_url);
  203. }
  204. //------------------------
  205. public function isMobileDevice(){
  206. $type_device=new Mobile_Detect();
  207. if(($type_device->isMobile())||($type_device->isTablet())){
  208. // echo "mobile";
  209. return true;
  210. }else{
  211. // echo "pc";
  212. return false;
  213. }
  214. }
  215. //----------------------------------
  216. public function saveLastConnectionDate($debug=0){
  217. $current_numero=Tools::getsession("num_conn");
  218. $sql_conn="select last_connexion from 3g_connexion where numero='$current_numero'";
  219. $rep=$this->database->executeOne($sql_conn,$debug);
  220. $res= Tools::convert_date_to_french($rep["last_connexion"]);
  221. $_SESSION["last_connexion_date"]=$res;
  222. return $res;
  223. }
  224. //-------------------------
  225. public function getLastConnectionDate($debug=0){
  226. return Tools::getsession("last_connexion_date");
  227. }
  228. //------------------------------
  229. public function ConvertVolumeOffre($value){
  230. $unit="Mo";
  231. $res=$value;
  232. if($value>=1024){
  233. $res=$value/1024;
  234. $unit="Go";
  235. }
  236. return $res." ".$unit;
  237. }
  238. //-----------------------------------
  239. public function ConvertVolumeWithoutUnit($value){
  240. $res=$value/(1024*1024);
  241. return round($res,2);
  242. }
  243. //------------------------
  244. public function ConvertConsoRatio($maxvalue,$conso_rest){
  245. return floor((($conso_rest/$maxvalue)*100));
  246. }
  247. //-----------------------------
  248. //--------------------------
  249. public function ConvertVolume($value){
  250. $unit="Mo";
  251. $nb_mo=($value/(1024*1024));
  252. $result=$nb_mo;
  253. $octet_rest=($value%(1024*1024));
  254. if($octet_rest==0){
  255. //on teste la valeur en giga
  256. $reste_giga=($nb_mo%1024);
  257. if($reste_giga==0){
  258. $result=$nb_mo/1024;
  259. $unit="Go";
  260. }
  261. }
  262. $result=round($result,2);
  263. if($result==0){
  264. $unit="Mo";
  265. }
  266. return Tools::formatfrechprice($result)." ".$unit;
  267. }
  268. //-------------------------
  269. public function setRedirectUrl(){
  270. $_SESSION["previous"]=$_SERVER["REQUEST_URI"];
  271. }
  272. //------------------------------------
  273. public function correct_captcha(){
  274. $securimage = new Securimage();
  275. // echo "cap".$securimage->check($_POST['captcha_code']);
  276. if ($securimage->check($_POST['captcha_code']) == false) {
  277. // echo "code incorrecte";
  278. return false;
  279. }else{
  280. return true;
  281. // echo "code _correcte";
  282. }
  283. }
  284. //-------------------------------------
  285. public function addMessage($type,$text,$prefix="msg"){
  286. $_SESSION[$prefix."type_error"]=$type;
  287. $_SESSION[$prefix."content"]=$text;
  288. }
  289. //------------------------------------
  290. public function getMessagetype($prefix="msg"){
  291. $res=$_SESSION[$prefix."type_error"];
  292. unset($_SESSION[$prefix."type_error"]);
  293. return $res;
  294. }
  295. public function getMessageContent($prefix="msg"){
  296. $res=$_SESSION[$prefix."content"];
  297. unset($_SESSION[$prefix."content"]);
  298. return $res;
  299. }
  300. //-------------------------------
  301. function generePasswordStrong($nbcaracters=8){
  302. $lettres="abcdefghijklmnopqrstpuvwxyz";
  303. $chiffres="0123456789";
  304. $result="";
  305. for($i=0;$i<$nbcaracters;$i++){
  306. $char_list= (mt_rand(0,1))? $lettres:$chiffres ;
  307. $index=mt_rand(0,intval(($char_list)-1));
  308. $char=$char_list[$index];
  309. $result.=$char;
  310. }
  311. return $result;
  312. }
  313. //------------------------------------
  314. //------------------------------------
  315. public function connect($user,$pass){
  316. }
  317. public function logoutnoreturn(){
  318. }
  319. public function status_connexion($unlogged="false"){
  320. if(!isset($_SESSION["islogged"])){
  321. return FALSE;
  322. }else{
  323. return true;
  324. }
  325. }
  326. //-----------------------------------------------
  327. function getUserInfos($key){
  328. }
  329. //-------------------------------------
  330. public function openSession($numero,$id_connexion,$equipement,$password){
  331. $_SESSION["islogged"]=true;
  332. $_SESSION["num_conn"]=$numero;
  333. $_SESSION["id_conn"]=$id_connexion;
  334. $_SESSION["equipement"]=$equipement;
  335. $_SESSION["password_conn"]=$password;
  336. }
  337. //--------------------------------------------
  338. function validEmail($value){
  339. return filter_var($value,FILTER_VALIDATE_EMAIL);
  340. }
  341. //----------------------------------------
  342. public function launchmail($dest,$mes,$sub="MOOV PORTAIL 3G",$nexp="MOOV PORTAIL 3G"){
  343. $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
  344. // echo "over";
  345. $mail->isMail(); // telling the class to use SMTP
  346. // $mail->IsSMTP();
  347. try {
  348. // $mail->Host = "mail.yourdomain.com"; // SMTP server
  349. // $mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
  350. // $mail->SMTPAuth = true; // enable SMTP authentication
  351. // $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
  352. // $mail->Host = "ssl://smtp.gmail.com"; // sets GMAIL as the SMTP server
  353. // $mail->Port = 465; // set the SMTP port for the GMAIL server
  354. // $mail->Username = "interactiveneo@gmail.com"; // GMAIL username
  355. // $mail->Password = "neographics"; // GMAIL password
  356. //$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)*/
  357. // GMAIL password
  358. // $mail->AddReplyTo('noreply@akasicars.com', '');
  359. $mail->AddAddress($dest);
  360. //$mail->AddAddress("interactiveneo@gmail.com");
  361. $mail->SetFrom('portail3g@moov.com', $nexp);
  362. $mail->AddReplyTo('rce@moov.com', '');
  363. $mail->Subject = $sub;
  364. $mail->CharSet = 'UTF-8';
  365. $mail->AltBody = ''; // optional - MsgHTML will create an alternate automatically
  366. $mail->MsgHTML($mes);
  367. // $mail->AddAttachment('images/phpmailer.gif'); // attachment
  368. //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  369. $mail->Send();
  370. $mail->ClearAddresses();
  371. $mail->AddAddress("interactiveneo@gmail.com");
  372. $mail->Send();
  373. // echo "Message Sent OK</p>\n";
  374. } catch (phpmailerException $e) {
  375. echo $e->errorMessage(); //Pretty error messages from PHPMailer
  376. } catch (Exception $e) {
  377. echo $e->getMessage(); //Boring error messages from anything else!
  378. }
  379. }
  380. //--------------------------------------------
  381. //-------------------------------------------------
  382. //----------------------------
  383. public function cryptdata($value){
  384. $alphabet="abcdefghiljkmnopqrstuvwxyz";
  385. $leure=$alphabet[mt_rand(0,25)];
  386. $value=base64_encode($value);
  387. $value=substr($value,0,2).$leure.substr($value,2);
  388. return $value;
  389. }
  390. //--------------------------------------------
  391. public function decrypt($value){
  392. $value=substr($value,0,2).substr($value,3);
  393. $value=base64_decode($value);
  394. return $value;
  395. }
  396. //----------------------------------
  397. //-------------------------------------------
  398. //---------------------------------------
  399. //-------------------------------------
  400. //------------------------------------------
  401. //----------------------------------------
  402. //-----------------------------------------
  403. //----------------------------------
  404. //-----------------------------------
  405. //------------------------------------
  406. //----------------------------------
  407. //---------------------------------
  408. //--------------------------------
  409. public function generateRandomcode(){
  410. $prefix=date('Y').date('m').date('d').date('H').date('i').date('s');
  411. $idunique=uniqid($prefix);
  412. return $idunique;
  413. }
  414. //----------------------------
  415. //----------------------------
  416. function checkbrowser(){
  417. $res=$this->browser_info();
  418. if(array_key_exists("msie",$res )){
  419. $version=intval($res["msie"]);
  420. if($version<7){
  421. $this->error_duel("Votre navigateur a de nombreuses failles de sécurité et des fonctionnalités manquantes,il n' est donc pas compatible avec cette opération,Veuillez le mettre à jour",true);
  422. }
  423. }
  424. }
  425. //---------------------------------
  426. function browser_info($agent=null) {
  427. // Declare known browsers to look for
  428. $known = array('msie', 'firefox', 'safari', 'webkit', 'opera', 'netscape',
  429. 'konqueror', 'gecko');
  430. // Clean up agent and build regex that matches phrases for known browsers
  431. // (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor
  432. // version numbers. E.g. "2.0.0.6" is parsed as simply "2.0"
  433. $agent = strtolower($agent ? $agent : $_SERVER['HTTP_USER_AGENT']);
  434. $pattern = '#(?<browser>' . join('|', $known) .
  435. ')[/ ]+(?<version>[0-9]+(?:\.[0-9]+)?)#';
  436. // Find all phrases (or return empty array if none found)
  437. if (!preg_match_all($pattern, $agent, $matches)) return array();
  438. // Since some UAs have more than one phrase (e.g Firefox has a Gecko phrase,
  439. // Opera 7,8 have a MSIE phrase), use the last one found (the right-most one
  440. // in the UA). That's usually the most correct.
  441. $i = count($matches['browser'])-1;
  442. return array($matches['browser'][$i] => $matches['version'][$i]);
  443. }
  444. //-------------------------------------------------
  445. //--------------------------
  446. public function getpaginglink($value){
  447. $p=$_SERVER["QUERY_STRING"];
  448. $b=strpos($p ,"&Page=");
  449. if($b===false){
  450. $p.="&Page=".$value;
  451. }else{
  452. $p=str_replace("&Page=".$this->getvalue("Page"),"&Page=".$value ,$p );
  453. }
  454. return "search_car_result.do?".$p;
  455. }
  456. //----------------------------
  457. public function getpaginglink2($value){
  458. $p=$_SERVER["QUERY_STRING"];
  459. $b=strpos($p,"&Page=" );
  460. // echo "paging";
  461. if($b===false){
  462. // echo "concat";
  463. $p.="&Page=".$value;
  464. }else{
  465. // echo " replace";
  466. $p=str_replace("&Page=".$this->getvalue("Page"),"&Page=".$value ,$p );
  467. }
  468. return "search_global.do?".$p;
  469. }
  470. //---------------------------
  471. public function getPaginationLink($value,$key,$uri){
  472. $p=$_SERVER["QUERY_STRING"];
  473. $b=strpos($p,$key."=" );
  474. // echo $p;
  475. // echo $value;
  476. if($b===false){
  477. $prefix="";
  478. if($p!="") $prefix="&";
  479. $p.=$prefix.$key."=".$value;
  480. // echo "ll";
  481. }else{
  482. $p=str_replace($key."=".$_GET[$key],$key."=".$value ,$p );
  483. // echo "rep";
  484. }
  485. return $uri."?".$p;
  486. }
  487. //---------------------------
  488. public function addCss($val){
  489. $res="";
  490. foreach($val as $key=>$value){
  491. $res.='<link rel="stylesheet" type="text/css" href="css/'.$value.'"/>';
  492. }
  493. $this->vue->assign_var("ADDCSS",$res );
  494. }
  495. //------------------------------
  496. public function addJs($val){
  497. $res="";
  498. foreach($val as $key=>$value){
  499. $res.='<script type="text/javascript" src="js/'.$value.'"></script>';
  500. }
  501. $this->vue->assign_var("ADDJS",$res );
  502. }
  503. public function generatePagination($lastpage,$limitpage,$url,$key,$pagesbornes=3){
  504. if($lastpage==0) return "";
  505. $Page=Tools::getvalue($key);
  506. if($Page=="") $Page=1;
  507. $pagination='<div class="pagination">';
  508. if($Page==1) {
  509. $pagination.='<span class="disabled">?</span>';
  510. }else{
  511. $pagination.='<a href="'.$this->getPaginationLink($Page-1,$key,$url).'">?</a>';
  512. }
  513. if($lastpage<$limitpage){
  514. for($i=1;$i<=$lastpage;$i++){
  515. $pagination.=($Page==$i)? '<span class="current">'.$i.'</span>':'<a href="'.$this->getPaginationLink($i,$key,$url).'">'.$i.'</a>';
  516. }
  517. }else{
  518. for($i=1;$i<=$pagesbornes;$i++){
  519. $pagination.=($Page==$i)? '<span class="current">'.$i.'</span>':'<a href="'.$this->getPaginationLink($i,$key,$url).'">'.$i.'</a>';
  520. }
  521. $pagination.="...";
  522. $in=$lastpage-$pagesbornes;
  523. for($j=$in+1;$j<=$lastpage;$j++){
  524. $pagination.=($Page==$j)? '<span class="current">'.$j.'</span>':'<a href="'.$this->getPaginationLink($j,$key,$url).'">'.$j.'</a>';
  525. }
  526. }
  527. if($Page==$lastpage){
  528. $pagination.='<span class="disabled">?</span>';
  529. }else{
  530. $pagination.='<a href="'.$this->getPaginationLink($Page+1,$key,$url).'">?</a>';
  531. }
  532. $pagination.='</div>';
  533. return $pagination;
  534. }
  535. //------------------------------------------------------------------------------
  536. }
  537. ?>