PageRenderTime 36ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/lms_debug/protected/controllers/LeadsController_24_feb_2014.php

https://gitlab.com/badelal143/lms_debug
PHP | 2890 lines | 2422 code | 215 blank | 253 comment | 403 complexity | 87137fca7de43a13e119048ab3b3ff12 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0
  1. <?php
  2. class LeadsController extends Controller
  3. {
  4. const SHARED_TITLE = "Admin Panel";
  5. /**
  6. * Declares class-based actions.
  7. */
  8. public function filters()
  9. {
  10. return array( 'accessControl',array(
  11. 'CHttpCacheFilter + view',
  12. 'cacheControl' => " max-age=604800, must-revalidate",
  13. ) ); // perform access control for CRUD operations
  14. }
  15. public function actions()
  16. {
  17. return array(
  18. // captcha action renders the CAPTCHA image displayed on the contact page
  19. 'captcha'=>
  20. array(
  21. 'class'=>'CCaptchaAction',
  22. 'backColor'=>0xFFFFFF,
  23. ),
  24. // page action renders "static" pages stored under 'protected/views/site/pages'
  25. // They can be accessed via: index.php?r=site/page&view=FileName
  26. 'page'=>array(
  27. 'class'=>'CViewAction',
  28. ),
  29. );
  30. }
  31. /**
  32. * This is the 'roles' action that is invoked
  33. * when an action is not explicitly requested by users.
  34. */
  35. public function actionlead_welcome()
  36. {
  37. $model = new WelcomeMaster();
  38. $model = WelcomeMaster::model()->find("moduleId = '1' ");
  39. $this->render('lead_welcome',array('model'=>$model));
  40. }
  41. /**
  42. * This is the 'roles' action that is invoked
  43. * when an action is not explicitly requested by users.
  44. */
  45. public function actionlead_list()
  46. {
  47. $relationManager = $_SESSION['relationalManager'];
  48. $managerMemberId = implode(",",array_unique(@$relationManager));
  49. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  50. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  51. } else {
  52. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  53. }
  54. //$modelLead = Lead::model()->findAll(" $querycondition ");
  55. $this->render('lead_list');
  56. }
  57. /**
  58. * This is the 'lead_list_allocator' action that is invoked
  59. * when an action is not explicitly requested by users.
  60. */
  61. public function actionlead_list_allocator()
  62. {
  63. // renders the view file 'protected/views/site/index.php'
  64. // using the default layout 'protected/views/layouts/main.php'
  65. $this->render('lead_list_allocator');
  66. }
  67. /**
  68. * This is the 'lead_list_allocator' action that is invoked
  69. * when an action is not explicitly requested by users.
  70. */
  71. public function actionfollowup_lead_list()
  72. {
  73. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  74. $relationManager = $_SESSION['relationalManager'];
  75. $managerMemberId = implode(",",array_unique(@$relationManager));
  76. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  77. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  78. } else {
  79. $querycondition = " startDate = '".@$today12PM."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  80. }
  81. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  82. $this->render('followup_lead_list');
  83. }
  84. public function actionfollowup_overall_lead_list()
  85. {
  86. $relationManager = $_SESSION['relationalManager'];
  87. $managerMemberId = implode(",",array_unique(@$relationManager));
  88. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  89. $querycondition = ' status="Pending" ';
  90. } else {
  91. $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  92. }
  93. //$modelLead = LeadFollowup::model()->findAll(" $querycondition ");
  94. $this->render('followup_overall_lead_list');
  95. }
  96. /**
  97. * This is the 'lead_list_allocator' action that is invoked
  98. * when an action is not explicitly requested by users.
  99. */
  100. public function actionlead_list_tc()
  101. {
  102. // renders the view file 'protected/views/site/index.php'
  103. // using the default layout 'protected/views/layouts/main.php'
  104. $this->render('lead_list_tc');
  105. }
  106. /**
  107. * This is the 'lead_list_allocator' action that is invoked
  108. * when an action is not explicitly requested by users.
  109. */
  110. public function actionjunk_lead_list()
  111. {
  112. //$modelLead = Lead::model()->findAll(" leadStatusId = '36' ");
  113. $this->render('junk_lead_list');
  114. }
  115. /**
  116. * This is the 'lead_list_allocator' action that is invoked
  117. * when an action is not explicitly requested by users.
  118. */
  119. public function actionduplicate_lead_list()
  120. {
  121. //$modelLead = Lead::model()->findAll(" leadStatusId = '10' ");
  122. $this->render('duplicate_lead_list');
  123. }
  124. public function actionclose_lead_list()
  125. {
  126. //$modelLead = Lead::model()->findAll(" leadStatusId = '7' ");
  127. $this->render('close_lead_list');
  128. }
  129. /**
  130. * This is the 'lead_list_allocator' action that is invoked
  131. * when an action is not explicitly requested by users.
  132. */
  133. public function actionallocated_lead_list()
  134. {
  135. $relationManager = $_SESSION['relationalManager'];
  136. $managerMemberId = implode(",",array_unique(@$relationManager));
  137. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  138. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  139. } else {
  140. $querycondition = " currentAllocatedId >0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  141. }
  142. //$modelLead = Lead::model()->findAll(" $querycondition ");
  143. $this->render('allocated_lead_list');
  144. }
  145. /**
  146. * This is the 'lead_list_allocator' action that is invoked
  147. * when an action is not explicitly requested by users.
  148. */
  149. public function actionleads_details()
  150. {
  151. // renders the view file 'protected/views/site/index.php'
  152. // using the default layout 'protected/views/layouts/main.php'
  153. //for follow up
  154. if(isset($_POST['LeadFollowup'])){
  155. if(isset($_POST['LeadFollowup']['chkActionValid']) && @$_POST['LeadFollowup']['chkActionValid']==1){
  156. $res = $this->actionlead_followup(@$_POST['LeadFollowup'],@$_POST['Lead']['leadStatusId']);
  157. $decodeRes = json_decode($res);
  158. if(@$decodeRes->status == 'success'){
  159. echo CJSON::encode(array(
  160. 'status'=>'success'
  161. ));
  162. } else {
  163. echo $res;
  164. }
  165. }
  166. }
  167. // end of for follow ups
  168. $leadId = @$_GET['leadId'];
  169. $actionId = @$_REQUEST['actionId'];
  170. $actionmodel=LeadFollowup::model()->findByPk($actionId);
  171. $model = new Lead();
  172. $this->performAjaxValidation($model);
  173. $model->scenario = 'Lead';
  174. $managerMemberId = implode(",",$_SESSION['relationalManager']);
  175. $chkAllocatedLeads = $managerMemberId?Lead::model()->findAll(array("select"=>" leadId","condition"=>" leadStatusId != '26' AND leadStatusId != '25' AND currentAllocatedId IN (".@$managerMemberId.") ")):'0';
  176. $allocatedArr=array();
  177. foreach($chkAllocatedLeads as $key=>$value){
  178. $allocatedArr[]=$chkAllocatedLeads[$key]->leadId;
  179. }
  180. //print_r($allocatedArr);
  181. //die;
  182. /*if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin'){
  183. if(!in_array($leadId,$allocatedArr)){
  184. $this->redirect(array('leads/lead_list'));
  185. }
  186. }*/
  187. if(!empty($leadId)){
  188. $model=Lead::model()->findByPk($leadId);
  189. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  190. if(count($chkrecentlyViewed) == 0){
  191. $recentlyViewed = new recentlyViewed;
  192. $recentlyViewed->setAttributes(array(
  193. 'userId' => Yii::app()->session->get('id'),
  194. 'leadId' => $leadId,
  195. 'moduleId' => 0,
  196. 'updatedOn' => $_SESSION['id'],
  197. 'updatedBy' => $_SESSION['id'],
  198. ));
  199. $recentlyViewed->save(false);
  200. }
  201. }
  202. if(isset($_POST['Lead']))
  203. {
  204. $model->setAttributes(array(
  205. 'updatedOn' => time(), //additional
  206. 'updatedBy' => $_SESSION['id'], //additional
  207. 'status' => 'Active', //additional //additional
  208. ));
  209. $prevLeadStatusId=$model->leadStatusId;
  210. foreach($_POST['Lead'] as $name=>$value)
  211. {
  212. if($model->leadStatusId==''){
  213. $model->leadStatusId=$model->leadStatusParentId;
  214. }
  215. if($model->email=='Email'){
  216. $model->email='';
  217. }
  218. if($model->name=='Name'){
  219. $model->name='';
  220. }
  221. if($model->address=='Address'){
  222. $model->address='';
  223. }
  224. if($model->children=="Children (Less than 25 Yrs)"){
  225. $model->children='';
  226. }
  227. if($model->ageGroup=="Age of eldest member"){
  228. $model->ageGroup='';
  229. }
  230. if($model->leadStatusId==''){
  231. $model->leadStatusId=$prevLeadStatusId;
  232. }
  233. if(@$leadId!='' && $model->leadStatusId!='34' && @$model->leadStatusId!='35'){
  234. $model->isRead='yes';
  235. }
  236. $model->$name=$value;
  237. }
  238. if(@$leadId!='' && $model->leadStatusId!='34'){
  239. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  240. }
  241. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  242. if(count($chkStatusMandatoryOrNot) > 0){
  243. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  244. if($condMandatory == 'No'){
  245. if($model->validate(array('mobile'))){
  246. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  247. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  248. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  249. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  250. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  251. $modelHistory = new LeadHistory();
  252. $modelHistory->scenario = 'LeadHistory';
  253. $modelHistory->setAttributes(array(
  254. 'leadId' => @$leadId, //additional data you want to insert
  255. 'updatedOn' => time(), //additional
  256. 'updatedBy' => $_SESSION['id'], //additional
  257. 'status' => 'Active', //additional
  258. ));
  259. foreach($_POST['Lead'] as $name1=>$value1)
  260. {
  261. if($modelHistory->leadStatusId==''){
  262. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  263. }
  264. if($model->leadStatusId==''){
  265. $model->leadStatusId=2;
  266. }
  267. $modelHistory->$name1=$value1;
  268. }
  269. $model->save(false);
  270. $modelHistory->save();
  271. CJSON::encode(array(
  272. 'status'=>'success'
  273. ));
  274. Yii::app()->end();
  275. }
  276. }
  277. }
  278. $model->save();
  279. if($model->validate()){
  280. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  281. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  282. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  283. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  284. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  285. $modelHistory = new LeadHistory();
  286. $modelHistory->scenario = 'LeadHistory';
  287. $modelHistory->setAttributes(array(
  288. 'leadId' => @$leadId, //additional data you want to insert
  289. 'updatedOn' => time(), //additional
  290. 'updatedBy' => $_SESSION['id'], //additional
  291. 'status' => 'Active', //additional
  292. ));
  293. foreach($_POST['Lead'] as $name1=>$value1)
  294. {
  295. if($modelHistory->leadStatusId==''){
  296. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  297. }
  298. if($model->leadStatusId==''){
  299. $model->leadStatusId=2;
  300. }
  301. $modelHistory->$name1=$value1;
  302. }
  303. $modelHistory->save();
  304. echo CJSON::encode(array(
  305. 'status'=>'success'
  306. ));
  307. Yii::app()->end();
  308. //Yii::app()->end();
  309. //die;
  310. //$this->redirect(array('leads/leads_details'));
  311. } else {
  312. $error = CActiveForm::validate($model);
  313. if($error!='[]')
  314. echo $error;
  315. Yii::app()->end();
  316. //$this->render('leads_details',array('model'=>$model));
  317. }
  318. } else {
  319. $this->render('leads_details',array('model'=>@$model,'actionmodel'=>@$actionmodel,'quotesmobile'=>@$model->mobile));
  320. }
  321. }
  322. protected function performAjaxValidation($models)
  323. {
  324. if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
  325. {
  326. echo CActiveForm::validate($models);
  327. Yii::app()->end();
  328. }
  329. }
  330. /**
  331. * This is the 'lead_list_allocator' action that is invoked
  332. * when an action is not explicitly requested by users.
  333. */
  334. public function actionlead_followup()
  335. {
  336. $actionId = @$_REQUEST['actionId'];
  337. $model = new LeadFollowup();
  338. $model->scenario = 'LeadFollowup';
  339. if(isset($actionId) && !empty($actionId)){
  340. $model=LeadFollowup::model()->findByPk($actionId);
  341. } else {
  342. }
  343. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  344. $model->scenario = 'LeadFollowupTask';
  345. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  346. $model->scenario = 'LeadFollowup';
  347. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  348. $model->scenario = 'LeadFollowup';
  349. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  350. $model->scenario = 'LeadFollowupNotes';
  351. }
  352. $this->performAjaxValidation($model);
  353. if(isset($_POST['LeadFollowup']))
  354. {
  355. $userId = $_POST['LeadFollowup']['userId'];
  356. $model->setAttributes(array(
  357. 'createdOn' => time(), //additional data you want to insert
  358. 'updatedOn' => time(), //additional
  359. 'updatedBy' => @$userId, //additional
  360. 'createdBy' => @$userId, //additional
  361. 'status' => 'Pending', //additional
  362. ));
  363. foreach($_POST['LeadFollowup'] as $name=>$value)
  364. {
  365. $model->$name=$value;
  366. }
  367. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  368. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  369. $prefix=substr(time(),0,5);
  370. $folder = 'siteupload/';
  371. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  372. if($model->notesFile !='')
  373. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  374. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  375. }
  376. if(@$_POST['LeadFollowup']['startDate']!='') {
  377. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  378. $model->startDate=@$startDateVal;
  379. if(@$_POST['LeadFollowup']['hour']!='') {
  380. $model->startDateWithTime=(@$startDateVal-300)+(@$_POST['LeadFollowup']['hour']*3600)+(@$_POST['LeadFollowup']['minutes']*60);
  381. }
  382. }
  383. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  384. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  385. $model->taskDueDate=@$taskDueDateVal;
  386. }
  387. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  388. $model->taskCompleted='yes';
  389. }
  390. if($model->validate()){
  391. $model->save();
  392. $leadId = $_POST['LeadFollowup']['leadId'];
  393. return CJSON::encode(array(
  394. 'status'=>'success'
  395. ));
  396. Yii::app()->end();
  397. } else {
  398. $error = CActiveForm::validate($model);
  399. if($error!='[]')
  400. return $error;
  401. Yii::app()->end();
  402. }
  403. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  404. }
  405. $this->redirect(array('leads/lead_list'));
  406. }
  407. /**
  408. * This is the 'lead_list_allocator' action that is invoked
  409. * when an action is not explicitly requested by users.
  410. */
  411. public function actionlead_followupcalender()
  412. {
  413. $actionId = @$_REQUEST['actionId'];
  414. $model = new LeadFollowup();
  415. $model->scenario = 'LeadFollowup';
  416. if(isset($actionId) && !empty($actionId)){
  417. $model=LeadFollowup::model()->findByPk($actionId);
  418. } else {
  419. }
  420. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  421. $model->scenario = 'LeadFollowupTask';
  422. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  423. $model->scenario = 'LeadFollowup';
  424. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  425. $model->scenario = 'LeadFollowup';
  426. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  427. $model->scenario = 'LeadFollowupNotes';
  428. }
  429. $this->performAjaxValidation($model);
  430. if(isset($_POST['LeadFollowup']))
  431. {
  432. $userId = $_POST['LeadFollowup']['userId'];
  433. $model->setAttributes(array(
  434. 'createdOn' => time(), //additional data you want to insert
  435. 'updatedOn' => time(), //additional
  436. 'updatedBy' => @$userId, //additional
  437. 'createdBy' => @$userId, //additional
  438. 'status' => 'Pending', //additional
  439. ));
  440. foreach($_POST['LeadFollowup'] as $name=>$value)
  441. {
  442. $model->$name=$value;
  443. }
  444. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  445. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  446. $prefix=substr(time(),0,5);
  447. $folder = 'siteupload/';
  448. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  449. if($model->notesFile !='')
  450. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  451. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  452. }
  453. if(@$_POST['LeadFollowup']['startDate']!='') {
  454. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  455. $model->startDate=@$startDateVal;
  456. }
  457. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  458. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  459. $model->taskDueDate=@$taskDueDateVal;
  460. }
  461. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  462. $model->taskCompleted='yes';
  463. }
  464. if($model->validate()){
  465. $model->save();
  466. $leadId = $_POST['LeadFollowup']['leadId'];
  467. echo CJSON::encode(array(
  468. 'status'=>'success'
  469. ));
  470. Yii::app()->end();
  471. } else {
  472. $error = CActiveForm::validate($model);
  473. if($error!='[]')
  474. return $error;
  475. Yii::app()->end();
  476. }
  477. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  478. }
  479. $this->redirect(array('leads/lead_list'));
  480. }
  481. public function actionlead_contacts()
  482. {
  483. // renders the view file 'protected/views/site/index.php'
  484. // using the default layout 'protected/views/layouts/main.php'
  485. $model = new LeadContacts();
  486. $model->scenario = 'LeadContacts';
  487. $this->performAjaxValidation($model);
  488. if(!empty($_GET['contactId']))
  489. {
  490. $leadContactId=$_GET['leadContactId'];
  491. $model=LeadContacts::model()->findByPk($leadContactId);
  492. }
  493. if(!empty($_POST['LeadContacts']['leadContactId']))
  494. {
  495. $leadContactId=$_POST['LeadContacts']['leadContactId'];
  496. $model=LeadContacts::model()->findByPk($leadContactId);
  497. }
  498. if(isset($_POST['LeadContacts']))
  499. {
  500. $userId = $_POST['LeadContacts']['userId'];
  501. $leadId = $_POST['LeadContacts']['leadId'];
  502. $model->setAttributes(array(
  503. 'createdOn' => time(), //additional data you want to insert
  504. 'updatedOn' => time(), //additional
  505. 'updatedBy' => @$userId, //additional
  506. 'createdBy' => @$userId, //additional
  507. 'status' => 'Active', //additional
  508. ));
  509. foreach($_POST['LeadContacts'] as $name=>$value)
  510. {
  511. $model->$name=$value;
  512. }
  513. if($model->validate()){
  514. $model->save();
  515. echo CJSON::encode(array(
  516. 'status'=>'success'
  517. ));
  518. Yii::app()->end();
  519. } else {
  520. $error = CActiveForm::validate($model);
  521. if($error!='[]')
  522. echo $error;
  523. Yii::app()->end();
  524. }
  525. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  526. }
  527. $this->redirect(array('leads/lead_list'));
  528. }
  529. public function actionChangeContactStatus()
  530. {
  531. $Id=$_REQUEST['contactId'];
  532. $leadId=$_REQUEST['leadId'];
  533. $status=$_REQUEST['status'];
  534. if(isset($status)&&($status=='Inactive')){
  535. $status="Active";
  536. } else {
  537. $status="Inactive";
  538. }
  539. if(!empty($Id))
  540. {
  541. $model=LeadContacts::model()->findByPk($Id);
  542. }
  543. else
  544. {
  545. $model = LeadContacts::model()->findAll();
  546. }
  547. $model->status=$status;
  548. $model->save();
  549. $this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  550. }
  551. /**
  552. * This is the 'roles' action that is invoked
  553. * when an action is not explicitly requested by users.
  554. */
  555. public function actioncreate_lead()
  556. {
  557. $model=new Lead();
  558. $model->scenario = 'Lead';
  559. if(!empty($_GET['leadId']))
  560. {
  561. $leadId=$_GET['leadId'];
  562. $model=Lead::model()->findByPk($leadId);
  563. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  564. if(count($chkrecentlyViewed) == 0){
  565. $recentlyViewed = new recentlyViewed;
  566. $recentlyViewed->setAttributes(array(
  567. 'userId' => Yii::app()->session->get('id'),
  568. 'leadId' => $leadId,
  569. 'moduleId' => 0,
  570. 'createdOn' => time(),
  571. 'updatedOn' => time(),
  572. 'updatedBy' => time(),
  573. 'createdBy' => time(),
  574. ));
  575. $recentlyViewed->save(false);
  576. }
  577. }
  578. if(!empty($_POST['Lead']['leadId']))
  579. {
  580. $leadId=$_POST['Lead']['leadId'];
  581. $model=Lead::model()->findByPk($leadId);
  582. }
  583. if(isset($_POST['Lead']))
  584. {
  585. $model->setAttributes(array(
  586. 'createdOn' => time(), //additional data you want to insert
  587. 'updatedOn' => time(), //additional
  588. 'updatedBy' => Yii::app()->session->get('id'), //additional
  589. 'createdBy' => Yii::app()->session->get('id'),
  590. ));
  591. foreach($_POST['Lead'] as $name=>$value)
  592. {
  593. $model->$name=$value;
  594. if($model->leadStatusId==''){
  595. $model->leadStatusId=$model->leadStatusParentId;
  596. }
  597. if($model->leadStatusId==''){
  598. $model->leadStatusId=34;
  599. }
  600. if($model->mobile=='Mobile*'){
  601. $model->mobile='';
  602. }
  603. if($model->email=='Email'){
  604. $model->email='';
  605. }
  606. if($model->name=='Name'){
  607. $model->name='';
  608. }
  609. if($model->address=='Address'){
  610. $model->address='';
  611. }
  612. if($model->children=="Children (Less than 25 Yrs)"){
  613. $model->children='';
  614. }
  615. if($model->ageGroup=="Age of eldest member"){
  616. $model->ageGroup='';
  617. }
  618. }
  619. if($model->leadSourceId=='' or empty($model->leadSourceId)){
  620. $model->leadSourceId = '2';
  621. }
  622. if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin') {
  623. @$model->leadStatusId=35;
  624. @$model->currentAllocatedId=Yii::app()->session->get('id');
  625. }
  626. if(@$leadId!='' && $model->leadStatusId!='34'){
  627. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  628. }
  629. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  630. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  631. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  632. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  633. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  634. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  635. if(count($chkStatusMandatoryOrNot) > 0){
  636. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  637. if($condMandatory == 'No'){
  638. if($model->validate(array('mobile'))){
  639. $mobileNumber = @$_POST['Lead']['mobile'];
  640. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  641. if(empty($checkJunkNumber)){
  642. $beforethreemonth = time()-7776000;
  643. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  644. if(empty($checkDuplicateNumber)){
  645. $model->save(false);
  646. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  647. } else {
  648. $duplicateLeadId = $checkDuplicateNumber->leadId;
  649. $model->leadStatusId='10';
  650. $model->duplicateLeadId=@$duplicateLeadId;
  651. $model->currentAllocatedId=$checkDuplicateNumber->currentAllocatedId;
  652. $model->save(false);
  653. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  654. }
  655. } else {
  656. $model->leadStatusId='36';
  657. $model->save(false);
  658. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  659. }
  660. $this->redirect(array('leads/lead_list'));
  661. // $model->save(false);
  662. // $this->redirect(array('leads/lead_list'));
  663. }
  664. }
  665. }
  666. if($model->leadStatusId==36){
  667. $model->save(false);
  668. $this->redirect(array('leads/lead_list'));
  669. } else {
  670. if($model->validate()){
  671. $mobileNumber = $_POST['Lead']['mobile'];
  672. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  673. if(empty($checkJunkNumber)){
  674. $beforethreemonth = time()-7776000;
  675. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  676. if(empty($checkDuplicateNumber)){
  677. $model->save();
  678. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  679. } else {
  680. $duplicateLeadId = $checkDuplicateNumber->leadId;
  681. $model->leadStatusId='10';
  682. $model->duplicateLeadId=@$duplicateLeadId;
  683. $model->save();
  684. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  685. }
  686. } else {
  687. $model->leadStatusId='36';
  688. $model->save();
  689. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  690. }
  691. $this->redirect(array('leads/lead_list'));
  692. } else {
  693. $this->render('create_lead',array('model'=>$model));
  694. }
  695. }
  696. } else {
  697. $this->render('create_lead',array('model'=>$model));
  698. }
  699. }
  700. public function actionAllocateLeads()
  701. {
  702. $Id = $_REQUEST['userids'];
  703. $teamleaderId = $_REQUEST['User']['id'];
  704. $userId = $_REQUEST['Team']['teamMemberId'];
  705. $updatedBy = @$_SESSION['id'];
  706. $temIds = Yii::app()->db->createCommand("select distinct teamId from teamUserMapping where userId='".@$teamleaderId."' and status='Active' order by id desc ")->queryAll();
  707. $teamId = $temIds[0]['teamId'];
  708. foreach($Id as $key=>$value){
  709. $model = new AllocatedLeads();
  710. $model->scenario = 'AllocatedLeads';
  711. $model->setAttributes(array(
  712. 'currentAllocatedDate' => time(), //additional data you want to insert
  713. 'createdOn' => time(), //additional data you want to insert
  714. 'updatedOn' => time(), //additional
  715. 'updatedBy' => @$updatedBy, //additional
  716. 'createdBy' => @$updatedBy, //additional
  717. 'leadStatusId' => '35', //additional //additional
  718. ));
  719. $leadId = @$value;
  720. $model->leadId = @$value;
  721. $model->userId = @$userId;
  722. $model->teamId = @$teamId;
  723. $model->teamLeaderId = @$teamleaderId;
  724. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  725. $model->allocatedId = null;
  726. $model->isNewRecord = true;
  727. $model->save();
  728. $model=new Lead();
  729. $model->scenario = 'Lead';
  730. $updatedOn = time();
  731. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  732. }
  733. //
  734. //$this->redirect(array('leads/lead_list'));
  735. $this->redirect(array('leads/fresh_leads'));
  736. }
  737. /**
  738. * This is the 'lead_list_allocator' action that is invoked
  739. * when an action is not explicitly requested by users.
  740. */
  741. public function actionlead_assign()
  742. {
  743. $model = new Lead();
  744. $model->scenario = 'Lead';
  745. $leadId = $_REQUEST['AssignLead']['leadId'];
  746. $userId = $_REQUEST['AssignLead']['userId'];
  747. $assign = $_REQUEST['AssignLead']['assign'];
  748. if($leadId!='') {
  749. $updatedOn = time();
  750. $chkleadStatus = Lead::model()->findByPk($leadId);
  751. $existsOrNot = $chkleadStatus['leadStatusId'];
  752. $leadStatusIdUpdate = $existsOrNot?$existsOrNot:'34';
  753. if($leadStatusIdUpdate == 34){
  754. $leadStatusIdUpdate = 35;
  755. } else {
  756. $leadStatusIdUpdate = $leadStatusIdUpdate;
  757. }
  758. if($assign=='open') {
  759. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>'','status'=>'Active','leadStatusId'=>34,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>''));
  760. } elseif($assign=='self'){
  761. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$userId,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  762. } else {
  763. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$assign,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  764. }
  765. echo CJSON::encode(array(
  766. 'status'=>'success'
  767. ));
  768. Yii::app()->end();
  769. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  770. } else {
  771. $this->redirect(array('leads/lead_list'));
  772. }
  773. }
  774. /**
  775. * This is the 'roles' action that is invoked
  776. * when an action is not explicitly requested by users.
  777. */
  778. public function actionarchive_leads()
  779. {
  780. // renders the view file 'protected/views/site/index.php'
  781. // using the default layout 'protected/views/layouts/main.php'
  782. $model=new Lead();
  783. $model=Lead::model()->findAll();
  784. $this->render('archive_leads',array('model'=>$model));
  785. }
  786. /**
  787. * This is the 'roles' action that is invoked
  788. * when an action is not explicitly requested by users.
  789. */
  790. public function actionbulk_import_leads()
  791. {
  792. // renders the view file 'protected/views/site/index.php'
  793. // using the default layout 'protected/views/layouts/main.php'
  794. $model=new Lead();
  795. $this->render('bulk_import_lead',array('model'=>$model));
  796. }
  797. /**
  798. * This is the 'roles' action that is invoked
  799. * when an action is not explicitly requested by users.
  800. */
  801. public function actionjunk_leads()
  802. {
  803. // renders the view file 'protected/views/site/index.php'
  804. // using the default layout 'protected/views/layouts/main.php'
  805. $this->render('junk_leads');
  806. }
  807. /**
  808. * This is the 'module master' action that is invoked
  809. * when an action is not explicitly requested by users.
  810. */
  811. public function actionmodule_master()
  812. {
  813. // renders the view file 'protected/views/site/index.php'
  814. // using the default layout 'protected/views/layouts/main.php'
  815. $model=new ModuleMaster();
  816. $model->scenario = 'ModuleMaster';
  817. if(!empty($_GET['moduleId']))
  818. {
  819. $moduleId=$_GET['moduleId'];
  820. $model=ModuleMaster::model()->findByPk($moduleId);
  821. }
  822. if(!empty($_POST['ModuleMaster']['moduleId']))
  823. {
  824. $moduleId=$_POST['ModuleMaster']['moduleId'];
  825. $model=ModuleMaster::model()->findByPk($moduleId);
  826. }
  827. if(isset($_POST['ModuleMaster']))
  828. {
  829. $model->setAttributes(array(
  830. 'createdOn' => time(), //additional data you want to insert
  831. 'updatedOn' => time(), //additional
  832. 'updatedBy' => time(), //additional
  833. 'createdBy' => time(),
  834. 'status' => 'Activated', //additional //additional
  835. ));
  836. foreach($_POST['ModuleMaster'] as $name=>$value)
  837. {
  838. $model->$name=$value;
  839. }
  840. if($model->validate()){
  841. $model->save();
  842. $model2=ModuleMaster::model()->findAll();
  843. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  844. Yii::app()->user->setFlash('module_master_msg_success','Successfully Inserted');
  845. } else {
  846. Yii::app()->user->setFlash('module_master_msg_error','Please check. error occured');
  847. $this->render('module_master',array('model'=>$model));
  848. }
  849. } else {
  850. $model2=ModuleMaster::model()->findAll();
  851. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  852. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  853. }
  854. }
  855. /**
  856. * This is the action to handle external exceptions.
  857. */
  858. public function actionError()
  859. {
  860. if($error=Yii::app()->errorHandler->error)
  861. {
  862. if(Yii::app()->request->isAjaxRequest)
  863. echo $error['message'];
  864. else
  865. $this->render('error', $error);
  866. }
  867. }
  868. /**
  869. * Displays the contact page
  870. */
  871. public function actionContact()
  872. {
  873. $model=new ContactForm;
  874. if(isset($_POST['ContactForm']))
  875. {
  876. $model->attributes=$_POST['ContactForm'];
  877. if($model->validate())
  878. {
  879. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  880. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  881. $headers="From: $name <{$model->email}>\r\n".
  882. "Reply-To: {$model->email}\r\n".
  883. "MIME-Version: 1.0\r\n".
  884. "Content-type: text/plain; charset=UTF-8";
  885. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  886. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  887. $this->refresh();
  888. }
  889. }
  890. $this->render('contact',array('model'=>$model));
  891. }
  892. /**
  893. * Displays the login page
  894. */
  895. public function actionLogin()
  896. {
  897. $model=new User;
  898. // if it is ajax validation request
  899. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  900. {
  901. echo CActiveForm::validate($model);
  902. Yii::app()->end();
  903. }
  904. // collect user input data
  905. if(isset($_POST['User']))
  906. {
  907. $model->attributes=$_POST['User'];
  908. // validate user input and redirect to the previous page if valid
  909. if($model->validate() && $model->login()){
  910. $this->redirect(array('masters/dashboard'));
  911. } else {
  912. $this->redirect(Yii::app()->user->returnUrl);
  913. }
  914. }
  915. // display the login form
  916. $this->render('login',array('model'=>$model));
  917. }
  918. /**
  919. * Logs out the current user and redirect to homepage.
  920. */
  921. public function actionLogout()
  922. {
  923. Yii::app()->user->logout();
  924. $this->redirect(Yii::app()->homeUrl);
  925. }
  926. public function getPageType()
  927. {
  928. return "Leads";
  929. }
  930. public function init(){
  931. $obj =new RecentlyViewedController(); // preparing object
  932. $data=$obj->actionUserRoleAccess();
  933. $moduleArray=array();
  934. if(Yii::app()->session->get('type')=='superadmin'){
  935. $moduleArray['read']='yes';
  936. $moduleArray['write']='yes';
  937. $moduleArray['delete']='yes';
  938. }else{
  939. foreach($data as $key=>$value){
  940. if($data[$key]->modules->moduleName=='Leads'){
  941. $moduleArray['moduleName']=$data[$key]->modules->moduleName;
  942. $moduleArray['read']=$data[$key]->read;
  943. $moduleArray['write']=$data[$key]->write;
  944. $moduleArray['delete']=$data[$key]->delete;
  945. }
  946. }
  947. }
  948. return $moduleArray;
  949. }
  950. public function getNameFromNumber($num) {
  951. $numeric = $num % 26;
  952. $letter = chr(65 + $numeric);
  953. $num2 = intval($num / 26);
  954. if ($num2 > 0) {
  955. return getNameFromNumber($num2 - 1) . $letter;
  956. } else {
  957. return $letter;
  958. }
  959. }
  960. /*function actionexportArchiveList()
  961. {
  962. // generate a resultset
  963. $model=new User;
  964. $model=User::model()->findAll();
  965. // render data to xlsx format and echo resultant file back to browser.
  966. ExcelExporter::sendAsXLS($model, true, 'closedLeads.xls');
  967. }*/
  968. public function actionDownloadLeadTemp(){
  969. Yii::import('ext.phpexcel.XPHPExcel');
  970. $objPHPExcel= XPHPExcel::createPHPExcel();
  971. $objPHPExcel->getProperties()->setCreator("LeadTemplate")
  972. ->setLastModifiedBy("LeadTemplate")
  973. ->setTitle("LeadTemplate")
  974. ->setSubject("LeadTemplate")
  975. ->setDescription("LeadTemplate.")
  976. ->setKeywords("LeadTemplate")
  977. ->setCategory("LeadTemplate");
  978. //echo $total_excelColumns=$this->getNameFromNumber(4);
  979. $total_excelColumns='I';
  980. // Rename worksheet
  981. $objPHPExcel->getActiveSheet()->setTitle('ClosedLeads');
  982. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  983. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  984. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
  985. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  986. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  987. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  988. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  989. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  990. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  991. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  992. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  993. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  994. array(
  995. 'font' => array(
  996. 'name' => 'Times New Roman',
  997. 'bold' => true,
  998. 'italic' => false,
  999. 'size' => 12
  1000. ),
  1001. 'borders' => array(
  1002. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1003. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1004. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1005. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1006. ),
  1007. 'alignment' => array(
  1008. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1009. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1010. 'wrap' => true
  1011. )
  1012. ),
  1013. 'A1:'.$total_excelColumns.'1'
  1014. );
  1015. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1016. // Add some data
  1017. $objPHPExcel->setActiveSheetIndex(0)
  1018. ->setCellValue('A1', 'Name')
  1019. ->setCellValue('B1', 'City')
  1020. ->setCellValue('C1', 'Email')
  1021. ->setCellValue('D1', 'Mobile')
  1022. ->setCellValue('E1', 'Suminsured')
  1023. ->setCellValue('F1', 'Age')
  1024. ->setCellValue('G1', 'No. Of Members')
  1025. ->setCellValue('H1', 'Date on submit')
  1026. ->setCellValue('I1', 'Lead Source');
  1027. // Miscellaneous glyphs, UTF-8
  1028. $objPHPExcel->setActiveSheetIndex(0)
  1029. ->setCellValue('A2', 'Lead Name')
  1030. ->setCellValue('B2', 'city')
  1031. ->setCellValue('C2', 'test@yesk.com')
  1032. ->setCellValue('D2', '9999999999')
  1033. ->setCellValue('E2', '56')
  1034. ->setCellValue('F2', '23')
  1035. ->setCellValue('G2', 'test')
  1036. ->setCellValue('H2', '07-Sep-2013')
  1037. ->setCellValue('I2', 'test');
  1038. //To create new sheet in current file
  1039. /*$objPHPExcel->createSheet(1);
  1040. $objPHPExcel->setActiveSheetIndex(1);
  1041. $objPHPExcel->getActiveSheet()->setTitle('Title');
  1042. */
  1043. // Redirect output to a clientÂ’s web browser (Excel5)
  1044. header('Content-Type: application/vnd.ms-excel');
  1045. header('Content-Disposition: attachment;filename="LeadTemplates.xls"');
  1046. header('Cache-Control: max-age=0');
  1047. // If you're serving to IE 9, then the following may be needed
  1048. header('Cache-Control: max-age=1');
  1049. // If you're serving to IE over SSL, then the following may be needed
  1050. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  1051. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1052. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1053. header ('Pragma: public'); // HTTP/1.0
  1054. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1055. $objWriter->save('php://output');
  1056. Yii::app()->end();
  1057. }
  1058. public function actionImportLeadTemplate(){
  1059. $model=new lead();
  1060. $data='';
  1061. $final_arr=@$_POST['final_arr']?@$_POST['final_arr']:'';
  1062. if(isset($_POST['ImportLeads']) && empty($final_arr) && !empty($_FILES['Lead']['name']['import'])){
  1063. Yii::import('ext.phpexcelreader.JPhpExcelReader');
  1064. $model->attributes='import';
  1065. $model->import=CUploadedFile::getInstance($model,'import');
  1066. $prefix=substr(time(),0,5);
  1067. $folder = '/tempdata';
  1068. $model->import->saveAs($folder.$prefix.$model->import);
  1069. $data=new JPhpExcelReader($folder.$prefix.$model->import);
  1070. //$this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1071. //$this->redirect(Yii::app()->createUrl('leads/bulk_import_leads'),array('data'=>$data,'model'=>$model));
  1072. $this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1073. }
  1074. if(isset($_POST['ImportLeads']) && !empty($final_arr) && isset($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1075. $final_arr = unserialize(urldecode($_POST["final_arr"]));
  1076. $dateTime=time();
  1077. for($i=0;$i<sizeof($final_arr);$i++)
  1078. {
  1079. $junkNumberQuery = Yii::app()->db->createCommand("SELECT `junkLeadNumberId` FROM `junkLeadNumberMaster` WHERE `junkLeadNumber` = '".@$final_arr[$i]['mobile']."' ")->queryAll();
  1080. $junkNumberResult = $junkNumberQuery;
  1081. //$duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' ")->queryAll();(Original, changed below by Baljeet)
  1082. $duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId`,`currentAllocatedId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' ")->queryAll();
  1083. $duplicateResult = ($duplicateQuery);
  1084. if(count($junkNumberResult) > 0){
  1085. $leadStatusId = '36';
  1086. $duplicateLeadId = '';
  1087. } elseif(count($duplicateResult)>0){
  1088. $leadStatusId = '10';
  1089. $duplicateLeadId = @$duplicateResult[0]['leadId'];
  1090. $currentAllocatedId = @$duplicateResult[0]['currentAllocatedId']; //added by baljeet
  1091. } else {
  1092. $leadStatusId = '34';
  1093. $duplicateLeadId = '';
  1094. }
  1095. $model=new lead();
  1096. $model->name=$final_arr[$i]['name'];
  1097. $model->cityId=$final_arr[$i]['cityId'];
  1098. $model->email=$final_arr[$i]['email'];
  1099. $model->mobile=$final_arr[$i]['mobile'];
  1100. $model->si=$final_arr[$i]['suminsured'];
  1101. $model->age=$final_arr[$i]['age'];
  1102. $model->members=$final_arr[$i]['noofmembers'];
  1103. $model->dateonSubmit=$final_arr[$i]['dateonsubmit'];
  1104. $model->leadSourceId=$final_arr[$i]['leadSourceId'];
  1105. $model->leadStatusId=$leadStatusId;
  1106. $model->duplicateLeadId=@$duplicateLeadId;
  1107. $model->currentAllocatedId=@$currentAllocatedId;
  1108. $model->productId='1';
  1109. $model->status='Active';
  1110. $model->createdOn=$dateTime;
  1111. $model->createdBy=Yii::app()->session->get('id');
  1112. $model->updatedOn=$dateTime;
  1113. $model->updatedBy=Yii::app()->session->get('id');
  1114. $model->isNewRecord = true;
  1115. $model->save(false);
  1116. }
  1117. $this->redirect(array('leads/lead_list'));
  1118. }
  1119. if(isset($_POST['ImportLeads']) && empty($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1120. $model->validate();
  1121. $this->render('bulk_import_lead',array('model'=>$model));
  1122. }
  1123. }
  1124. public function actionleadSearch()
  1125. {
  1126. $searched = new Lead();
  1127. $this->render('lead_search',array('searched'=>$searched));
  1128. }
  1129. public function actionExportExcel()
  1130. {
  1131. // It calls the actionCreateExcel to generates excel reports'
  1132. $this->actionCreateExcel();
  1133. }
  1134. public function actionCreateExcel(){
  1135. //Here is the code to set conditions for fetch records from database
  1136. $criteria = new CDbCriteria;
  1137. $criteria->select = 't.*,`city`.`city`, `state`.`state`, `leadSourceMaster`.`leadSourceTitle`,`leadSourceMaster`.`leadSourceCode`,`leadStageMaster`.`leadStage`,`leadStatus`.`leadStatus`, `customerTypeMaster`.`customerType`,`productMaster`.`productName`,`policyTypeMaster`.`policyType`,`planTypeMaster`.`planType`,`campaign`.`campaignName`';
  1138. $criteria->join ='LEFT JOIN city ON (city.cityId = t.cityId) LEFT JOIN state ON (state.stateId = t.stateId) LEFT JOIN leadSourceMaster ON (leadSourceMaster.leadSourceId = t.leadSourceId) LEFT JOIN leadStageMaster ON (leadStageMaster.leadStageId = t.leadStageId)LEFT JOIN leadStatus ON (leadStatus.leadStatusId = t.leadStatusId)LEFT JOIN customerTypeMaster ON (customerTypeMaster.customerTypeId = t.customerTypeId)LEFT JOIN productMaster ON (productMaster.productId = t.productId)LEFT JOIN policyTypeMaster ON (policyTypeMaster.policyTypeId = t.policyTypeId)LEFT JOIN planTypeMaster ON (planTypeMaster.planTypeId = t.planTypeId)LEFT JOIN campaign ON (campaign.campaignId = t.campaignId)';
  1139. $criteria->condition='t.status != "Allocated" AND t.leadStatusId != "25" AND t.leadStatusId != "26" ';
  1140. $criteria->order='leadId DESC';
  1141. $model=new LeadReport();
  1142. $model->scenario = 'LeadReport';
  1143. $reportmodel=LeadReport::model()->findAll($criteria);
  1144. $data=array();
  1145. $datas = $reportmodel;
  1146. foreach($datas as $key=>$value){
  1147. $data[$key]=$value;
  1148. }
  1149. if(count($data)>0){
  1150. Yii::import('ext.phpexcel.XPHPExcel');
  1151. $objPHPExcel= XPHPExcel::createPHPExcel();
  1152. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1153. ->setLastModifiedBy("ReligareLMS")
  1154. ->setTitle("Office 2007 XLSX Test Document")
  1155. ->setSubject("Office 2007 XLSX Test Document")
  1156. ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
  1157. ->setKeywords("office 2007 openxml php")
  1158. ->setCategory("Test result file");
  1159. $total_excelColumns=$this->getNameFromNumber(8);
  1160. // Rename worksheet
  1161. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1162. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1163. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1164. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1165. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1166. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1167. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1168. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1169. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1170. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1171. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1172. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1173. array(
  1174. 'font' => array(
  1175. 'name' => 'Times New Roman',
  1176. 'bold' => true,
  1177. 'italic' => false,
  1178. 'size' => 12
  1179. ),
  1180. 'borders' => array(
  1181. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1182. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1183. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1184. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1185. ),
  1186. 'alignment' => array(
  1187. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1188. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1189. 'wrap' => true
  1190. )
  1191. ),
  1192. 'A1:'.$total_excelColumns.'1'
  1193. );
  1194. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1195. // Add some data
  1196. $objPHPExcel->setActiveSheetIndex(0)
  1197. ->setCellValue('A1', 'SNO.')
  1198. ->setCellValue('B1', 'Name')
  1199. ->setCellValue('C1', 'Mobile')
  1200. ->setCellValue('D1', 'Email')
  1201. ->setCellValue('E1', 'Lead Stage')
  1202. ->setCellValue('F1', 'Date and Time')
  1203. ->setCellValue('G1', 'UTM Code')
  1204. ->setCellValue('H1', 'status');
  1205. // Miscellaneous glyphs, UTF-8
  1206. $i=0;
  1207. $k=2;
  1208. $sn=1;
  1209. while($i<count($data)){
  1210. $objPHPExcel->setActiveSheetIndex(0)
  1211. ->setCellValue('A'.$k,$sn)
  1212. ->setCellValue('B'.$k,$data[$i]['name'])
  1213. ->setCellValue('C'.$k,$data[$i]['mobile'])
  1214. ->setCellValue('D'.$k,$data[$i]['email'])
  1215. ->setCellValue('E'.$k,$data[$i]['leadStage'])
  1216. ->setCellValue('F'.$k,date("d/m/y h:i A",$data[$i]['createdOn']))
  1217. ->setCellValue('G'.$k,$data[$i]['leadSourceCode'])
  1218. ->setCellValue('H'.$k,$data[$i]['status']);
  1219. $i++;$k++;$sn++;}
  1220. // Redirect output to a clientÂ’s web browser (Excel5)
  1221. header('Content-Type: application/vnd.ms-excel');
  1222. header('Content-Disposition: attachment;filename="lead_report.xls"');
  1223. header('Cache-Control: max-age=0');
  1224. // If you're serving to IE 9, then the following may be needed
  1225. header('Cache-Control: max-age=1');
  1226. // If you're serving to IE over SSL, then the following may be needed
  1227. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1228. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1229. header ('Pragma: public'); // HTTP/1.0
  1230. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1231. $objWriter->save('php://output');
  1232. Yii::app()->end();
  1233. }
  1234. else{
  1235. $model = new Lead();
  1236. $model = Lead::model()->findAll("status = 'Active'");
  1237. $this->render('lead_list',array('model'=>$model));
  1238. }
  1239. }
  1240. public function actiongetSourceResults(){
  1241. $models=new Lead();
  1242. $type=@$_REQUEST['type'];
  1243. $searchTxt=@$_REQUEST['searchTxt'];
  1244. if(isset($searchTxt) && !empty($searchTxt)){
  1245. $this->renderPartial('searchSourceLeads',array('searchTxt'=>$searchTxt,'type'=>@$type));
  1246. } else {
  1247. if($type=='fresh'){
  1248. $functs="fresh_leads";
  1249. }
  1250. if($type=='new'){
  1251. $functs="lead_list";
  1252. }
  1253. if($type=='duplicate'){
  1254. $functs="duplicate_lead_list";
  1255. }
  1256. if($type=='dupforday'){
  1257. $functs="dup_forthe_day_lead_list";
  1258. }
  1259. if($type=='junk'){
  1260. $functs="junk_lead_list";
  1261. }
  1262. if($type=='allocated'){
  1263. $functs="allocated_lead_list";
  1264. }
  1265. if($type=='cip'){
  1266. $functs="cip_lead_list";
  1267. }
  1268. if($type=='plc'){
  1269. $functs="plc_lead_list";
  1270. }
  1271. if($type=='closed'){
  1272. $functs="close_lead_list";
  1273. }
  1274. if($type==''){
  1275. $functs="lead_list";
  1276. }
  1277. echo Yii::app()->createUrl('leads/'.@$functs);
  1278. exit;
  1279. }
  1280. }
  1281. public function actionAutocompleteSearch(){
  1282. $models=new Lead();
  1283. $term=@$_REQUEST['term'];
  1284. $type=@$_REQUEST['type'];
  1285. if($type=="fresh"){
  1286. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1287. }
  1288. if($type=="new"){
  1289. $relationManager = $_SESSION['relationalManager'];
  1290. $managerMemberId = implode(",",array_unique(@$relationManager));
  1291. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1292. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  1293. } else {
  1294. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1295. }
  1296. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1297. //$models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1298. }
  1299. if($type=="duplicate"){
  1300. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '10' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1301. }
  1302. if($type=="dupforday"){
  1303. $today12PMs = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1304. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '10' and `createdOn` > '".@$today12PMs."' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1305. }
  1306. if($type=="junk"){
  1307. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '36' and concat(name,mobile,email) like '%$term%'","order"=>"leadId desc"));
  1308. }
  1309. if($type=="allocated"){
  1310. $relationManager = $_SESSION['relationalManager'];
  1311. $managerMemberId = implode(",",array_unique(@$relationManager));
  1312. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1313. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  1314. } else {
  1315. $querycondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1316. }
  1317. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1318. }
  1319. if($type=="followup"){
  1320. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1321. $relationManager = $_SESSION['relationalManager'];
  1322. $managerMemberId = implode(",",array_unique(@$relationManager));
  1323. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1324. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  1325. } else {
  1326. $querycondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1327. }
  1328. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1329. }
  1330. if($type=="allfollowup"){
  1331. $relationManager = $_SESSION['relationalManager'];
  1332. $managerMemberId = implode(",",array_unique(@$relationManager));
  1333. $currentDate=date('d-m-Y',time());
  1334. $starttimestamp=strtotime($currentDate);
  1335. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1336. $querycondition = ' status="Pending" ';
  1337. } else {
  1338. $querycondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1339. }
  1340. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1341. }
  1342. if($type=="closed"){
  1343. $relationManager = $_SESSION['relationalManager'];
  1344. $managerMemberId = implode(",",array_unique(@$relationManager));
  1345. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1346. $querycondition = "leadStatusId = '7'";
  1347. } else {
  1348. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1349. }
  1350. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and concat(name,mobile,email) like '%$term%' ");
  1351. }
  1352. if($type=="cip"){
  1353. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=3")->queryAll();
  1354. $CIPids = array();
  1355. if(count($contactInProgList) > 0){
  1356. for($w=0;$w<count($contactInProgList);$w++){
  1357. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1358. }
  1359. } else {
  1360. @$CIPids[] = '';
  1361. }
  1362. @$CIPids = implode(",",@$CIPids);
  1363. $relationManager = $_SESSION['relationalManager'];
  1364. $managerMemberId = implode(",",array_unique(@$relationManager));
  1365. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1366. $querycondition = " leadStatusId IN ( ".@$CIPids." ) ";
  1367. } else {
  1368. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1369. }
  1370. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1371. }
  1372. if($type=="plc"){
  1373. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=41")->queryAll();
  1374. $CIPids = array();
  1375. if(count($contactInProgList) > 0){
  1376. for($w=0;$w<count($contactInProgList);$w++){
  1377. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1378. }
  1379. } else {
  1380. @$CIPids[] = '';
  1381. }
  1382. @$CIPids = implode(",",@$CIPids);
  1383. $relationManager = $_SESSION['relationalManager'];
  1384. $managerMemberId = implode(",",array_unique(@$relationManager));
  1385. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1386. $querycondition = " leadStatusId IN ( ".@$CIPids." ) ";
  1387. } else {
  1388. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1389. }
  1390. $models = Lead::model()->findAll(" $querycondition and concat(name,mobile,email) like '%$term%'");
  1391. }
  1392. if($type=="cld"){
  1393. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1394. $relationManager = $_SESSION['relationalManager'];
  1395. $managerMemberId = implode(",",array_unique(@$relationManager));
  1396. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1397. $querycondition = 'leadStatusId = 12 AND startDate = "'.@$today12PM.'" ';
  1398. } else {
  1399. $querycondition = "leadStatusId = 12 AND startDate = '".@$today12PM."' AND userId IN (".@$managerMemberId.") ";
  1400. }
  1401. $models = LeadFollowup::model()->findAll(" $querycondition and description like '%$term%'");
  1402. }
  1403. if($type=="followup" or $type=="allfollowup" or $type=="cld"){
  1404. $arr = array();
  1405. foreach($models as $model) {
  1406. $arr[] = array(
  1407. 'label'=>substr($model->description,0,10), // label for dropdown list
  1408. 'value'=>substr($model->description,0,10), // value for input field
  1409. 'id'=>$model->leadFollowupId, // return value from autocomplete
  1410. );
  1411. }
  1412. if(count($models) > 0){
  1413. $arr['totalRecords'] = array(
  1414. 'totalRecords'=>count($models), // return value from autocomplete
  1415. );
  1416. }
  1417. }else {
  1418. $arr = array();
  1419. foreach($models as $model) {
  1420. $arr[] = array(
  1421. 'label'=>$model->mobile?$model->mobile.($model->name?'/'.$model->name:'').($model->email?'/'.$model->email:''):'', // label for dropdown list
  1422. 'value'=>$model->mobile?$model->mobile:$model->name, // value for input field
  1423. 'id'=>$model->leadId, // return value from autocomplete
  1424. );
  1425. }
  1426. if(count($models) > 0){
  1427. $arr['totalRecords'] = array(
  1428. 'totalRecords'=>count($models), // return value from autocomplete
  1429. );
  1430. }
  1431. }
  1432. echo CJSON::encode($arr);
  1433. Yii::app()->end();
  1434. //$this->renderPartial('searchLeads');
  1435. }
  1436. public function actionAutocompleteSearchSource(){
  1437. $models=new Lead();
  1438. $term=@$_REQUEST['term'];
  1439. $type=@$_REQUEST['type'];
  1440. if($type=="fresh"){
  1441. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and concat(leadSourceTitle) like '%$term%'","order"=>"leadId desc"));
  1442. }
  1443. if($type=="new"){
  1444. $relationManager = $_SESSION['relationalManager'];
  1445. $managerMemberId = implode(",",array_unique(@$relationManager));
  1446. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1447. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' ";
  1448. } else {
  1449. $querycondition = " leadStatusId = '35' AND currentAllocatedId > 0 AND isRead='no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1450. }
  1451. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%'");
  1452. //$models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1453. }
  1454. if($type=="duplicate"){
  1455. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '10' and leadSourceTitle like '%$term%'","order"=>"leadId desc"));
  1456. }
  1457. if($type=="junk"){
  1458. $models=Lead::model()->with("leadSourceDetails")->findAll(array("condition"=>"leadStatusId = '36' and leadSourceTitle like '%$term%'","order"=>"leadId desc"));
  1459. }
  1460. if($type=="allocated"){
  1461. $relationManager = $_SESSION['relationalManager'];
  1462. $managerMemberId = implode(",",array_unique(@$relationManager));
  1463. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1464. $querycondition = " currentAllocatedId>0 AND isRead = 'yes'";
  1465. } else {
  1466. $querycondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1467. }
  1468. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%'");
  1469. }
  1470. if($type=="followup"){
  1471. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1472. $relationManager = $_SESSION['relationalManager'];
  1473. $managerMemberId = implode(",",array_unique(@$relationManager));
  1474. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1475. $querycondition = ' startDate = "'.@$today12PM.'" and status="Pending" ';
  1476. } else {
  1477. $querycondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1478. }
  1479. $models = LeadFollowup::model()->findAll(" $querycondition and description leadSourceTitle '%$term%'");
  1480. }
  1481. if($type=="closed"){
  1482. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1483. $relationManager = $_SESSION['relationalManager'];
  1484. $managerMemberId = implode(",",array_unique(@$relationManager));
  1485. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1486. $querycondition = "leadStatusId = '7'";
  1487. } else {
  1488. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1489. }
  1490. $models = Lead::model()->with("leadSourceDetails")->findAll(" $querycondition and leadSourceTitle like '%$term%' ");
  1491. }
  1492. if($type=="followup"){
  1493. $arr = array();
  1494. foreach($models as $model) {
  1495. $arr[] = array(
  1496. 'label'=>substr($model->description,0,10), // label for dropdown list
  1497. 'value'=>substr($model->description,0,10), // value for input field
  1498. 'id'=>$model->leadFollowupId, // return value from autocomplete
  1499. );
  1500. }
  1501. if(count($models) > 0){
  1502. $arr['totalRecords'] = array(
  1503. 'totalRecords'=>count($models), // return value from autocomplete
  1504. );
  1505. }
  1506. }else {
  1507. $arr = array();
  1508. foreach($models as $model) {
  1509. $arr[] = array(
  1510. 'label'=>$model->mobile?$model->mobile:$model->name, // label for dropdown list
  1511. 'value'=>$model->mobile?$model->mobile:$model->name, // value for input field
  1512. 'id'=>$model->leadId, // return value from autocomplete
  1513. );
  1514. }
  1515. if(count($models) > 0){
  1516. $arr['totalRecords'] = array(
  1517. 'totalRecords'=>count($models), // return value from autocomplete
  1518. );
  1519. }
  1520. }
  1521. echo CJSON::encode($arr);
  1522. Yii::app()->end();
  1523. //$this->renderPartial('searchLeads');
  1524. }
  1525. public function actionAutocompleteSearchRes(){
  1526. $models=new Lead();
  1527. $term=@$_REQUEST['id'];
  1528. $type=@$_REQUEST['type'];
  1529. $models=Lead::model()->findAll(array("condition"=>"leadStatusId = '34' AND currentAllocatedId<1 and name like '%$term%'","order"=>"leadId desc"));
  1530. $arr = array();
  1531. $this->renderPartial('searchLeads',array('name'=>$term));
  1532. }
  1533. public function actionexportArchiveList(){
  1534. $Leadname = @$_REQUEST['name'];
  1535. $Leadstatus = @$_REQUEST['status'];
  1536. $leadStage = @$_REQUEST['statge'];
  1537. $cond ='';
  1538. if(isset($Leadname) && !empty($Leadname)){
  1539. $cond .=" AND name like '%".@$Leadname."%'";
  1540. }
  1541. if(isset($Leadstatus) && !empty($Leadstatus)){
  1542. $cond .=" AND leadStatusId = '".@$Leadstatus."'";
  1543. }
  1544. if(isset($leadStage) && !empty($leadStage)){
  1545. $cond .=" AND leadStageId = '".@$leadStage."'";
  1546. }
  1547. $dataProvider = new CActiveDataProvider('Lead', array('criteria'=>array(
  1548. 'condition'=>' FROM_UNIXTIME(updatedOn) >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) '.@$cond.' ',
  1549. 'order'=>'',
  1550. )));
  1551. $iterator = new CDataProviderIterator($dataProvider);
  1552. Yii::import('ext.phpexcel.XPHPExcel');
  1553. $objPHPExcel= XPHPExcel::createPHPExcel();
  1554. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1555. ->setLastModifiedBy("ReligareLMS")
  1556. ->setTitle("Office 2007 XLSX Leads Document")
  1557. ->setSubject("Office 2007 XLSX Leads Document")
  1558. ->setDescription("Archive Leads.")
  1559. ->setKeywords("Archive Leads")
  1560. ->setCategory("Archive Leads");
  1561. // Rename worksheet
  1562. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1563. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1564. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1565. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1566. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1567. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1568. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1569. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1570. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1571. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1572. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1573. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1574. array(
  1575. 'font' => array(
  1576. 'name' => 'Times New Roman',
  1577. 'bold' => true,
  1578. 'italic' => false,
  1579. 'size' => 12
  1580. ),
  1581. 'borders' => array(
  1582. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1583. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1584. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1585. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1586. ),
  1587. 'alignment' => array(
  1588. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1589. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1590. 'wrap' => true
  1591. )
  1592. ),
  1593. 'A1:H1'
  1594. );
  1595. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1596. // Add some data
  1597. $objPHPExcel->setActiveSheetIndex(0)
  1598. ->setCellValue('A1', 'SNO.')
  1599. ->setCellValue('B1', 'Name')
  1600. ->setCellValue('C1', 'Mobile')
  1601. ->setCellValue('D1', 'Email')
  1602. ->setCellValue('E1', 'Lead Stage')
  1603. ->setCellValue('F1', 'Date and Time')
  1604. ->setCellValue('G1', 'UTM Code')
  1605. ->setCellValue('H1', 'status');
  1606. // Miscellaneous glyphs, UTF-8
  1607. $i=0;
  1608. $k=2;
  1609. $sn=1;
  1610. foreach($iterator as $data) {
  1611. $objPHPExcel->setActiveSheetIndex(0)
  1612. ->setCellValue('A'.$k,$sn)
  1613. ->setCellValue('B'.$k,$data->name)
  1614. ->setCellValue('C'.$k,$data->mobile)
  1615. ->setCellValue('D'.$k,$data->email)
  1616. ->setCellValue('E'.$k,$data['leadStageDetails']['leadStage'])
  1617. ->setCellValue('F'.$k,date("d/m/y h:i A",$data->createdOn))
  1618. ->setCellValue('G'.$k,$data['leadSourceDetails']['leadSourceCode'])
  1619. ->setCellValue('H'.$k,$data->status);
  1620. $i++;$k++;$sn++;}
  1621. // Redirect output to a clientÂ’s web browser (Excel5)
  1622. header('Content-Type: application/vnd.ms-excel');
  1623. header('Content-Disposition: attachment;filename="lead_report.xls"');
  1624. header('Cache-Control: max-age=0');
  1625. // If you're serving to IE 9, then the following may be needed
  1626. header('Cache-Control: max-age=1');
  1627. // If you're serving to IE over SSL, then the following may be needed
  1628. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1629. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1630. header ('Pragma: public'); // HTTP/1.0
  1631. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1632. $objWriter->save('php://output');
  1633. Yii::app()->end();
  1634. }
  1635. public function actiongetCityList()
  1636. {
  1637. $data=City::model()->findAll(array('condition'=>'stateId=:stateId and status=:status','params'=>array(':stateId'=>(int) $_POST['stateId'],'status'=>'Active')));
  1638. $data=CHtml::listData($data,'cityId','city');
  1639. echo '<select class="styled" name="Lead[cityId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" onchange="changeText();">';
  1640. echo '<option value="" selected="selected">Select City</option>';
  1641. foreach($data as $value=>$name)
  1642. {
  1643. echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
  1644. }
  1645. echo '</select>';
  1646. echo '<span id="changeText" class="customStyleSelectBox" style="display: block;width:97px;"><span class="customStyleSelectBoxInner" style="width: 81px; display: block;">Select City</span></span>';
  1647. }
  1648. public function actiongetLeadStatus()
  1649. {
  1650. if(isset($_POST['parentId']) && !empty($_POST['parentId'])){
  1651. $data=LeadStatus::model()->findAll(array('condition'=>'parentId=:parentId and status=:status','params'=>array(':parentId'=>(int) @$_POST['parentId'],'status'=>'Active')));
  1652. $data=CHtml::listData($data,'leadStatusId','leadStatus');
  1653. echo '<select class="styled" name="Lead[leadStatusId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" id="leadprimarystatus" onchange="changeStatusText();getActionRes(this.value);">';
  1654. echo '<option value="" selected="selected">Select lead Status</option>';
  1655. foreach($data as $value=>$name)
  1656. {
  1657. echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name));
  1658. }
  1659. echo '</select>';
  1660. } else {
  1661. echo '<select class="styled" name="Lead[leadStatusId]" style="position: absolute; opacity: 0; font-size: 12px; height: 25px;" id="leadprimarystatus" onchange="changeStatusText();getActionRes(this.value);">';
  1662. echo '<option value="" selected="selected">Select lead Status</option>';
  1663. echo '</select>';
  1664. }
  1665. echo '<span id="changeStatusText" class="customStyleSelectBox" style="display: block;min-width:142px;"><span class="customStyleSelectBoxInner" style="width: 81px; display: block;">Select lead Status</span></span>';
  1666. }
  1667. public function actionexportLeads(){
  1668. $model=new Lead();
  1669. $type=@$_REQUEST['type'];
  1670. $relationManager = @$_SESSION['relationalManager'];
  1671. $managerMemberId = implode(",",array_unique(@$relationManager));
  1672. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1673. if($type=="freshLeads"){
  1674. if(@$_SESSION['isAllocator']=='yes') {
  1675. $querycondition = " leadStatusId = '34' AND currentAllocatedId<1";
  1676. } else {
  1677. $querycondition = " leadStatusId = '34' AND currentAllocatedId<1";
  1678. }
  1679. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1680. 'condition'=>@$querycondition,
  1681. 'order'=>'',
  1682. ),
  1683. 'pagination'=>false,
  1684. ));
  1685. }
  1686. if($type=="newLeads"){
  1687. if(@$_SESSION['isAllocator']=='yes') {
  1688. $querycondition = " leadStatusId = '35' AND currentAllocatedId >0 AND isRead = 'no'";
  1689. } else {
  1690. $querycondition = " leadStatusId = '35' AND currentAllocatedId >0 AND isRead = 'no' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1691. }
  1692. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1693. 'condition'=>@$querycondition,
  1694. 'order'=>'',
  1695. ),
  1696. 'pagination'=>false,
  1697. ));
  1698. }
  1699. if($type=="allocatedLeads"){
  1700. if(@$_SESSION['isAllocator']=='yes') {
  1701. $queryCondition = " currentAllocatedId>0 AND isRead = 'yes' ";
  1702. } else {
  1703. $queryCondition = " currentAllocatedId>0 AND isRead = 'yes' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1704. }
  1705. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1706. 'condition'=>@$queryCondition,
  1707. 'order'=>'',
  1708. )));
  1709. }
  1710. if($type=="Allfollowup"){
  1711. $currentDate=date('d-m-Y',time());
  1712. $starttimestamp=strtotime($currentDate);
  1713. if(@$_SESSION['isAllocator']=='yes') {
  1714. $queryCondition = ' status="Pending" and userId = "'.@$_SESSION['id'].'" ';
  1715. } else {
  1716. $queryCondition = " status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1717. }
  1718. $dataProvider=new CActiveDataProvider('LeadFollowup', array('criteria'=>array(
  1719. 'condition'=>@$queryCondition,
  1720. 'order'=>'leadFollowupId DESC',
  1721. )));
  1722. }
  1723. if($type=="followupLeads"){
  1724. $currentDate=date('d-m-Y',time());
  1725. $starttimestamp=strtotime($currentDate);
  1726. if(@$_SESSION['isAllocator']=='yes') {
  1727. $queryCondition = ' startDate = "'.@$starttimestamp.'" and status="Pending" and userId = "'.@$_SESSION['id'].'" ';
  1728. } else {
  1729. $queryCondition = " startDate = '".@$starttimestamp."' AND status = 'Pending' AND userId IN (".@$managerMemberId.") ";
  1730. }
  1731. $dataProvider=new CActiveDataProvider('LeadFollowup', array('criteria'=>array(
  1732. 'condition'=>@$queryCondition,
  1733. 'order'=>'leadFollowupId DESC',
  1734. )));
  1735. }
  1736. if($type=="duplicateLeads"){
  1737. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1738. 'condition'=>' leadStatusId = "10" ',
  1739. 'order'=>'leadId DESC',
  1740. )));
  1741. }
  1742. if($type=="dupforday"){
  1743. $today12PM = mktime(0,0,0,date("m"),date("d"),date("Y"));
  1744. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1745. 'condition'=>' leadStatusId = "10" AND createdOn > "'.@$today12PM.'" ',
  1746. 'order'=>'leadId DESC',
  1747. )));
  1748. }
  1749. if($type=="junkLeads"){
  1750. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1751. 'condition'=>' leadStatusId = "36" ',
  1752. 'order'=>'leadId DESC',
  1753. )));
  1754. }
  1755. if($type=="closeLeads"){
  1756. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1757. $querycondition = "leadStatusId = '7' ";
  1758. } else {
  1759. $querycondition = " leadStatusId = '7' AND currentAllocatedId IN (".@$managerMemberId.") ";
  1760. }
  1761. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1762. 'condition'=>@$querycondition,
  1763. 'order'=>'',
  1764. ),
  1765. 'pagination'=>false,
  1766. ));
  1767. }
  1768. if($type=="cip"){
  1769. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=3")->queryAll();
  1770. $CIPids = array();
  1771. if(count($contactInProgList) > 0){
  1772. for($w=0;$w<count($contactInProgList);$w++){
  1773. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1774. }
  1775. } else {
  1776. @$CIPids[] = '';
  1777. }
  1778. @$CIPids = implode(",",@$CIPids);
  1779. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1780. $querycondition = "leadStatusId IN ( ".@$CIPids." ) ";
  1781. } else {
  1782. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1783. }
  1784. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1785. 'condition'=>@$querycondition,
  1786. 'order'=>'',
  1787. ),
  1788. 'pagination'=>false,
  1789. ));
  1790. }
  1791. if($type=="plc"){
  1792. $contactInProgList=Yii::app()->db->createCommand("select leadStatus.leadStatus,leadStatusId from leadStatus where parentId=41")->queryAll();
  1793. $CIPids = array();
  1794. if(count($contactInProgList) > 0){
  1795. for($w=0;$w<count($contactInProgList);$w++){
  1796. @$CIPids[] = @$contactInProgList[$w]['leadStatusId'];
  1797. }
  1798. } else {
  1799. @$CIPids[] = '';
  1800. }
  1801. @$CIPids = implode(",",@$CIPids);
  1802. if(@$_SESSION['isAllocator']=='yes' or Yii::app()->session->get('type')=='superadmin') {
  1803. $querycondition = "leadStatusId IN ( ".@$CIPids." ) ";
  1804. } else {
  1805. $querycondition = " leadStatusId IN ( ".@$CIPids." ) AND currentAllocatedId IN (".@$managerMemberId.") ";
  1806. }
  1807. $dataProvider=new CActiveDataProvider('Lead', array('criteria'=>array(
  1808. 'condition'=>@$querycondition,
  1809. 'order'=>'',
  1810. ),
  1811. 'pagination'=>false,
  1812. ));
  1813. }
  1814. if($type=="followupLeads" or $type=="Allfollowup"){
  1815. $iterator = new CDataProviderIterator($dataProvider);
  1816. Yii::import('ext.phpexcel.XPHPExcel');
  1817. $objPHPExcel= XPHPExcel::createPHPExcel();
  1818. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1819. ->setLastModifiedBy("ReligareLMS")
  1820. ->setTitle("Office 2007 XLSX Leads Document")
  1821. ->setSubject("Office 2007 XLSX Leads Document")
  1822. ->setDescription("Archive Leads.")
  1823. ->setKeywords("Archive Leads")
  1824. ->setCategory("Archive Leads");
  1825. // Rename worksheet
  1826. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1827. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1828. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1829. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1830. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1831. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1832. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1833. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1834. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1835. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1836. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1837. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1838. array(
  1839. 'font' => array(
  1840. 'name' => 'Times New Roman',
  1841. 'bold' => true,
  1842. 'italic' => false,
  1843. 'size' => 12
  1844. ),
  1845. 'borders' => array(
  1846. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1847. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1848. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1849. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1850. ),
  1851. 'alignment' => array(
  1852. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1853. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1854. 'wrap' => true
  1855. )
  1856. ),
  1857. 'A1:H1'
  1858. );
  1859. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1860. // Add some data
  1861. $objPHPExcel->setActiveSheetIndex(0)
  1862. ->setCellValue('A1', 'SNO.')
  1863. ->setCellValue('B1', 'Name')
  1864. ->setCellValue('C1', 'Mobile')
  1865. ->setCellValue('D1', 'Email')
  1866. ->setCellValue('E1', 'Action Type')
  1867. ->setCellValue('F1', 'Date and Time')
  1868. ->setCellValue('G1', 'Description')
  1869. ->setCellValue('H1', 'Owner');
  1870. // Miscellaneous glyphs, UTF-8
  1871. $i=0;
  1872. $k=2;
  1873. $sn=1;
  1874. foreach($iterator as $data) {
  1875. $objPHPExcel->setActiveSheetIndex(0)
  1876. ->setCellValue('A'.$k,$sn)
  1877. ->setCellValue('B'.$k,$data->leadDetails->name)
  1878. ->setCellValue('C'.$k,$data->leadDetails->mobile)
  1879. ->setCellValue('D'.$k,$data->leadDetails->email)
  1880. ->setCellValue('E'.$k,$data->actionType)
  1881. ->setCellValue('F'.$k,date("d/m/y h:i A",$data->createdOn))
  1882. ->setCellValue('G'.$k,$data->description)
  1883. ->setCellValue('H'.$k,(@$data->userId==@$data->leadDetails->createdBy)?@$data->ownerDetails->firstName." ".$data->ownerDetails->lastName."(C)":(@$data->ownerDetails->firstName?@$data->ownerDetails->firstName." ".$data->ownerDetails->lastName:"NA"));
  1884. $i++;$k++;$sn++;}
  1885. } else {
  1886. $iterator = new CDataProviderIterator($dataProvider);
  1887. Yii::import('ext.phpexcel.XPHPExcel');
  1888. $objPHPExcel= XPHPExcel::createPHPExcel();
  1889. $objPHPExcel->getProperties()->setCreator("ReligareLMS")
  1890. ->setLastModifiedBy("ReligareLMS")
  1891. ->setTitle("Office 2007 XLSX Leads Document")
  1892. ->setSubject("Office 2007 XLSX Leads Document")
  1893. ->setDescription("Archive Leads.")
  1894. ->setKeywords("Archive Leads")
  1895. ->setCategory("Archive Leads");
  1896. // Rename worksheet
  1897. $objPHPExcel->getActiveSheet()->setTitle('Sample Excel');
  1898. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1899. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1900. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(6);
  1901. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1902. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1903. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1904. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1905. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1906. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1907. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1908. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  1909. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1910. array(
  1911. 'font' => array(
  1912. 'name' => 'Times New Roman',
  1913. 'bold' => true,
  1914. 'italic' => false,
  1915. 'size' => 12
  1916. ),
  1917. 'borders' => array(
  1918. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1919. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1920. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1921. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1922. ),
  1923. 'alignment' => array(
  1924. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1925. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1926. 'wrap' => true
  1927. )
  1928. ),
  1929. 'A1:I1'
  1930. );
  1931. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1932. // Add some data
  1933. $objPHPExcel->setActiveSheetIndex(0)
  1934. ->setCellValue('A1', 'SNO.')
  1935. ->setCellValue('B1', 'Name')
  1936. ->setCellValue('C1', 'Mobile')
  1937. ->setCellValue('D1', 'Email')
  1938. ->setCellValue('E1', 'Lead Stage')
  1939. ->setCellValue('F1', 'Date and Time')
  1940. ->setCellValue('G1', 'Lead Status')
  1941. ->setCellValue('H1', 'Owner')
  1942. ->setCellValue('I1', 'status');
  1943. // Miscellaneous glyphs, UTF-8
  1944. $i=0;
  1945. $k=2;
  1946. $sn=1;
  1947. foreach($iterator as $data) {
  1948. $objPHPExcel->setActiveSheetIndex(0)
  1949. ->setCellValue('A'.$k,$sn)
  1950. ->setCellValue('B'.$k,$data->name)
  1951. ->setCellValue('C'.$k,$data->mobile)
  1952. ->setCellValue('D'.$k,$data->email)
  1953. ->setCellValue('E'.$k,$data['leadStageDetails']['leadStage'])
  1954. ->setCellValue('F'.$k,date("d/m/y h:i A",$data->createdOn))
  1955. ->setCellValue('G'.$k,@$data->leadStatusDetails->leadStatus)
  1956. ->setCellValue('H'.$k,(@$data->currentAllocatedId==@$data->createdBy)?@$data->ownerDetails->firstName." ".$data->ownerDetails->lastName."(C)":(@$data->ownerDetails->firstName?@$data->ownerDetails->firstName." ".$data->ownerDetails->lastName:"NA"))
  1957. ->setCellValue('I'.$k,$data->status);
  1958. $i++;$k++;$sn++;}
  1959. }
  1960. // Redirect output to a clientÂ’s web browser (Excel5)
  1961. header('Content-Type: application/vnd.ms-excel');
  1962. header('Content-Disposition: attachment;filename="lead_report.xls"');
  1963. header('Cache-Control: max-age=0');
  1964. // If you're serving to IE 9, then the following may be needed
  1965. header('Cache-Control: max-age=1');
  1966. // If you're serving to IE over SSL, then the following may be needed
  1967. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1968. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1969. header ('Pragma: public'); // HTTP/1.0
  1970. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1971. $objWriter->save('php://output');
  1972. Yii::app()->end();
  1973. }
  1974. public function actionapiPremimum()
  1975. {
  1976. $model = new Lead();
  1977. global $INDIVIDUAL,$FAMILYFLOATER,$GroupCareArray;
  1978. $INDIVIDUAL = array(
  1979. "200000" => "001",
  1980. "300000" => "003",
  1981. "400000" => "005",
  1982. "500000" => "007",
  1983. "700000" => "009",
  1984. "1000000" => "011",
  1985. "1500000" => "013",
  1986. "2000000" => "015",
  1987. "2500000" => "017",
  1988. "5000000" => "019",
  1989. "6000000" => "021"
  1990. );
  1991. $FAMILYFLOATER = array(
  1992. "200000" => "002",
  1993. "300000" => "004",
  1994. "400000" => "006",
  1995. "500000" => "008",
  1996. "700000" => "010",
  1997. "1000000" => "012",
  1998. "1500000" => "014",
  1999. "2000000" => "016",
  2000. "2500000" => "018",
  2001. "5000000" => "020",
  2002. "6000000" => "022"
  2003. );
  2004. $query['ageGroupOfEldestMember']=@$_REQUEST['ageGroupOfEldestMember'];
  2005. $query['coverTypeCd']=@$_REQUEST['coverTypeCd'];
  2006. $query['productId']=@$productId1;
  2007. $query['productTerm']=@$_REQUEST['productTerm'];
  2008. $query['sumInsured']=@$_REQUEST['sumInsured'];
  2009. if(@$_REQUEST['coverTypeCd']=="INDIVIDUAL"){
  2010. $sumInsured=@$_REQUEST['sumInsured'];
  2011. if(@$sumInsured>0){
  2012. $sumInsured1=$INDIVIDUAL[@$sumInsured];
  2013. }
  2014. $query['numberOfAdult']=@$_REQUEST['numberOfAdult'];
  2015. $query['numberOfChildren']=0;
  2016. }else{
  2017. $sumInsured=@$_REQUEST['sumInsured'];
  2018. if(@$sumInsured>0){
  2019. $sumInsured1=$FAMILYFLOATER[@$sumInsured];
  2020. }
  2021. $query['numberOfAdult']=@$_REQUEST['numberOfAdult'];
  2022. $query['numberOfChildren']=@$_REQUEST['numberOfChildren'];
  2023. }
  2024. $query['sumInsured1']=@$sumInsured1;
  2025. /*$_SESSION['ageGroupOfEldestMember']=@$query['ageGroupOfEldestMember'];// assign value to session for product tab
  2026. $_SESSION['coverTypeCd'] =@$query['coverTypeCd'];// assign value to session for product tab
  2027. $_SESSION['numberOfAdult'] =@$query['numberOfAdult']+$query['numberOfChildren'];// assign value to session for product tab
  2028. $_SESSION['numberOfChildren'] =@$query['numberOfChildren'];// assign value to session for product tab
  2029. $_SESSION['sumInsured'] =@$sumInsured;// assign value to session for product tab*/
  2030. $premiumArray=$this->csvToArray('tempdata/care_premium.csv');
  2031. $totalMember=$query['numberOfAdult']+$query['numberOfChildren'];
  2032. $planKey=$query['coverTypeCd'].":".$query['ageGroupOfEldestMember'].":".@$totalMember.":".$query['numberOfChildren'].":".$query['sumInsured1'];
  2033. $exactPremiumArray=$this->search(@$premiumArray,'Plan',@$planKey);
  2034. $exactCarePremiumArray=explode(":",$exactPremiumArray[0]['Premium']);
  2035. $tenureidx = $_REQUEST['tenure']-1;
  2036. $carePremium = $exactCarePremiumArray[@$tenureidx];
  2037. //print_r($exactCarePremiumArray);
  2038. $ncppremiumArray=$this->csvToArray('tempdata/ncb_premium.csv');
  2039. $ncbtotalMember=$query['numberOfAdult']+$query['numberOfChildren'];
  2040. $ncbplanKey=$query['coverTypeCd'].":".$query['ageGroupOfEldestMember'].":".@$ncbtotalMember.":".$query['numberOfChildren'].":".$query['sumInsured1'];
  2041. $ncbexactPremiumArray=$this->search(@$ncppremiumArray,'Plan',@$ncbplanKey);
  2042. $exactNCBPremiumArray=explode(":",@$ncbexactPremiumArray[0]['Premium']);
  2043. //$tenureidx = $_REQUEST['tenure']-1;
  2044. $ncbPremium = @$exactNCBPremiumArray[@$tenureidx];
  2045. $addCarePremium = str_replace(',','',@$carePremium);
  2046. $addNCBPremium = str_replace(',','',@$ncbPremium);
  2047. $finalNcbPremium = number_format($addNCBPremium+$addCarePremium);
  2048. //print_r($premiumArray);
  2049. echo trim(@$carePremium).':'.trim(@$finalNcbPremium);
  2050. // echo @$exactPremiumArray[0]['Premium'];
  2051. //$this->render('lead_search',array('searched'=>$searched));
  2052. }
  2053. function csvToArray($csvFileName){
  2054. $row = 1;
  2055. $dataArray=array();
  2056. $columnArray=array();
  2057. $k=0;
  2058. $i=0;
  2059. if (($handle = fopen($csvFileName, "r")) !== FALSE) {
  2060. while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) {
  2061. $num = count($data);
  2062. if($k==0){
  2063. for ($c=0; $c < $num; $c++) {
  2064. $columnArray[$c]=@$data[$c];
  2065. }
  2066. }else{
  2067. for ($c=0; $c < $num; $c++) {
  2068. $columnName=$columnArray[$c];
  2069. $dataArray[$i][$columnName]=@$data[$c];
  2070. }
  2071. $i++;
  2072. }
  2073. $k++;
  2074. $row++;
  2075. }
  2076. fclose($handle);
  2077. }
  2078. return $dataArray;
  2079. }
  2080. function search($array, $key, $value){
  2081. $results = array();
  2082. if (is_array($array))
  2083. {
  2084. if (isset($array[$key]) && $array[$key] == $value)
  2085. $results[] = $array;
  2086. foreach ($array as $subarray){
  2087. $results = array_merge($results, $this->search($subarray, $key, $value));
  2088. }
  2089. }
  2090. return $results;
  2091. }
  2092. function quotesResults(){
  2093. }
  2094. public function actiongetPlanDetails(){
  2095. }
  2096. public function actionleadCreation(){
  2097. include_once("api/api.php");
  2098. $pageList = $this->xml2array(@file_get_contents(ADMINURL.'resource/product_subcategory.xml'),'1','');
  2099. $pageListArray = @$pageList['ProductSubCategory'];
  2100. $subcategoryList = $this->subcategory_page_array($pageListArray);
  2101. if(sanitize_data(@$_REQUEST['productId'])>0){
  2102. for($i=0; $i<count($subcategoryList); $i++){
  2103. if($subcategoryList[$i]["subCategoryId"]==sanitize_data($_REQUEST['productId']))
  2104. {
  2105. @$productId1="Care";
  2106. }
  2107. }
  2108. }else{
  2109. @$productId1="";
  2110. }
  2111. $query['coverTypeCd']=(@$_REQUEST['coverTypeCd']);
  2112. $query['productId']=@$productId1;
  2113. $query['sumInsured']=(@$_REQUEST['sumInsured']);
  2114. // if(@$_REQUEST['coverTypeCd']=="INDIVIDUAL"){
  2115. // switch(@$_REQUEST['sumInsured']){
  2116. // case '200000': $sumInsured1="001";
  2117. // break;
  2118. // case '300000': $sumInsured1="003";
  2119. // break;
  2120. // case '500000': $sumInsured1="005";
  2121. // break;
  2122. // case '1000000': $sumInsured1="007";
  2123. // break;
  2124. // default: $sumInsured1="007";
  2125. // break;
  2126. // }
  2127. // }else{
  2128. // switch(@$_REQUEST['sumInsured']){
  2129. // case '200000': $sumInsured1="002";
  2130. // break;
  2131. // case '300000': $sumInsured1="004";
  2132. // break;
  2133. // case '500000': $sumInsured1="006";
  2134. // break;
  2135. // case '1000000': $sumInsured1="008";
  2136. // break;
  2137. // default: $sumInsured1="008";
  2138. // break;
  2139. // }
  2140. // }
  2141. $tenure=(@$_REQUEST['tenure']);
  2142. $leadstage=(@$_POST['leadstage']);
  2143. $subject=(@$_POST['subject']);
  2144. $query['sumInsured1']=(@$_REQUEST['sumInsured']);
  2145. $query['firstname']=(@$_REQUEST["firstname"]);
  2146. $query['lastname']="";
  2147. $query['emailaddress1']=(@$_REQUEST["emailaddress1"]);
  2148. $query['telephone1']=(@$_REQUEST["telephone1"]);
  2149. $query['mobilephone']=(@$_REQUEST["mobilephone"]);
  2150. $query['premium']=(@$_REQUEST["premium".@$tenure]);
  2151. if(@$_SESSION['agentId']!=''){
  2152. $query['agentid']=@$_SESSION['agentId'];
  2153. }else{
  2154. $query['agentid']=AGENTID;
  2155. }
  2156. $query['noofyears']=@$tenure;
  2157. $query['quoteid']=time();
  2158. if(@$leadstage!=''){
  2159. $query['leadstage']=@$leadstage;
  2160. }else{
  2161. $query['leadstage']="SendQuotation";
  2162. }
  2163. if(@$subject!=''){
  2164. $query['subject']=@$subject." - ".(@$_REQUEST["mobilephone"]);
  2165. }else{
  2166. $query['subject']="Web-".(@$_REQUEST["mobilephone"]);
  2167. }
  2168. $dataArray= $this->LeadCreation($query);
  2169. $_SESSION["quotationReferenceNum"]=$query['quoteid'];
  2170. $_SESSION['mobileSend']="2";
  2171. $_SESSION['mobilephone']=(@$_REQUEST["mobilephone"]);
  2172. }
  2173. public function actionportalProposal(){
  2174. define("_SITEURL", "http://" . @$_SERVER['SERVER_NAME']. '/religare') ;
  2175. define("ADMINURL", "../", true);
  2176. global $INDIVIDUAL,$FAMILYFLOATER,$GroupCareArray;
  2177. $GroupCareArray = array("200000" => "2 Lac + 2 Lac", "300000" => "3 Lac + 3 Lac", "400000" => "4 Lac + 4 Lac", "500000" => "5 Lac + 5 Lac", "700000" => "7 Lac + 7 Lac", "1000000" => "10 Lac + 10 Lac", "1500000" => "15 Lac + 10 Lac", "2000000" => "20 Lac + 10 Lac", "2500000" => "25 Lac + 10 Lac", "5000000" => "50 Lac + 10 Lac", "6000000" => "60 Lac + 10 Lac");
  2178. $INDIVIDUAL = array(
  2179. "200000" => "001",
  2180. "300000" => "003",
  2181. "400000" => "005",
  2182. "500000" => "007",
  2183. "700000" => "009",
  2184. "1000000" => "011",
  2185. "1500000" => "013",
  2186. "2000000" => "015",
  2187. "2500000" => "017",
  2188. "5000000" => "019",
  2189. "6000000" => "021"
  2190. );
  2191. $FAMILYFLOATER = array(
  2192. "200000" => "002",
  2193. "300000" => "004",
  2194. "400000" => "006",
  2195. "500000" => "008",
  2196. "700000" => "010",
  2197. "1000000" => "012",
  2198. "1500000" => "014",
  2199. "2000000" => "016",
  2200. "2500000" => "018",
  2201. "5000000" => "020",
  2202. "6000000" => "022"
  2203. );
  2204. $WEBSUMINSURED = array(
  2205. "200000" => "1",
  2206. "300000" => "2",
  2207. "400000" => "3",
  2208. "500000" => "4",
  2209. "700000" => "5",
  2210. "1000000" => "6",
  2211. "1500000" => "7",
  2212. "2000000" => "8",
  2213. "2500000" => "9",
  2214. "5000000" => "10",
  2215. "6000000" => "11"
  2216. );
  2217. $WEBSUMINSURED1 = array(
  2218. "1" => "200000",
  2219. "2" => "300000",
  2220. "3" => "400000",
  2221. "4" => "500000",
  2222. "5" => "700000",
  2223. "6" => "1000000",
  2224. "7" => "1500000",
  2225. "8" => "2000000",
  2226. "9" => "2500000",
  2227. "10" => "5000000",
  2228. "11" => "6000000"
  2229. );
  2230. $proposalURL="https://rhicluat.religare.com/portalui/PortalExtProposal.run";
  2231. $pageList = $this->xml2array(@file_get_contents('resource/product_subcategory.xml'),'1','');
  2232. $pageListArray = @$pageList['ProductSubCategory'];
  2233. $subcategoryList = $this->subcategory_page_array($pageListArray);
  2234. $productId=(@$_POST['productId']);
  2235. $sumInsured=(@$_POST['sumInsured']);
  2236. $tenure=(@$_POST['premium']);
  2237. $totalAdults=(@$_POST['numberOfAdult']);
  2238. $numberOfChildren=(@$_POST['numberOfChildren']);
  2239. $numberOfAdult=$totalAdults-$numberOfChildren;
  2240. $mobileNumber=(@$_POST['mobile']);
  2241. $_SESSION['mobilephone']=$mobileNumber;
  2242. if($productId>0){
  2243. for($i=0; $i<count($subcategoryList); $i++){
  2244. if($subcategoryList[$i]["subCategoryId"]==$productId)
  2245. {
  2246. @$productId1=$subcategoryList[$i]["productCode"];
  2247. }
  2248. }
  2249. }else{
  2250. @$productId1="";
  2251. }
  2252. if(($tenure==1) || ($tenure==2) || ($tenure==3)){}else{header("Location: "._SITEURL);exit;}
  2253. if($productId1==""){header("Location: "._SITEURL);exit;}else{}
  2254. if(($numberOfChildren==0) || ($numberOfChildren==1) || ($numberOfChildren==2) || ($numberOfChildren==3) || ($numberOfChildren==4)){}else{ header("Location: "._SITEURL);exit;}
  2255. if($totalAdults>1){
  2256. $ageGroupOfEldestMember=(@$_POST['ageGroupOfEldestMember']);
  2257. switch($ageGroupOfEldestMember){
  2258. case '18 - 24': $ageGroupOfEldestMember="18 - 24";
  2259. break;
  2260. case '25 - 35': $ageGroupOfEldestMember="25 - 35";
  2261. break;
  2262. case '36 - 40': $ageGroupOfEldestMember="36 - 40";
  2263. break;
  2264. case '41 - 45': $ageGroupOfEldestMember="41 - 45";
  2265. break;
  2266. case '46 - 50': $ageGroupOfEldestMember="46 - 50";
  2267. break;
  2268. case '51 - 55': $ageGroupOfEldestMember="51 - 55";
  2269. break;
  2270. case '56 - 60': $ageGroupOfEldestMember="56 - 60";
  2271. break;
  2272. case '61 - 65': $ageGroupOfEldestMember="61 - 65";
  2273. break;
  2274. case '66 - 70': $ageGroupOfEldestMember="66 - 70";
  2275. break;
  2276. case '71 - 75': $ageGroupOfEldestMember="71 - 75";
  2277. break;
  2278. case '76 - 99': $ageGroupOfEldestMember="76 - 99";
  2279. break;
  2280. default: $ageGroupOfEldestMember="";
  2281. break;
  2282. }
  2283. if($ageGroupOfEldestMember==""){header("Location: "._SITEURL);exit;}else{}
  2284. $coverType="FAMILYFLOATER";
  2285. if(@$sumInsured>0){
  2286. $sumInsured1=$FAMILYFLOATER[@$sumInsured];
  2287. }
  2288. if($sumInsured1==""){header("Location: "._SITEURL);exit;}else{}
  2289. //$url1="&numberOfAdult=".@$numberOfAdult."&numberOfChildren=".@$numberOfChildren;
  2290. // $url="Location: ".@$proposalURL."?productFamily=HEALTH&pCode=".@$productId1."&coverType=FAMILYFLOATER&ageGroupOfEldestMember=".@$ageGroupOfEldestMember."&sumInsured=".@$sumInsured1."&tenure=".@$tenure.$url1."&mobileNum=".@$_POST['mobile'];
  2291. }else if($totalAdults=="1"){
  2292. $ageGroupOfEldestMember=@$_POST['ageGroupOfEldestMember'];
  2293. switch($ageGroupOfEldestMember){
  2294. case '5 - 24': $ageGroupOfEldestMember="5 - 24";
  2295. break;
  2296. case '25 - 35': $ageGroupOfEldestMember="25 - 35";
  2297. break;
  2298. case '36 - 40': $ageGroupOfEldestMember="36 - 40";
  2299. break;
  2300. case '41 - 45': $ageGroupOfEldestMember="41 - 45";
  2301. break;
  2302. case '46 - 50': $ageGroupOfEldestMember="46 - 50";
  2303. break;
  2304. case '51 - 55': $ageGroupOfEldestMember="51 - 55";
  2305. break;
  2306. case '56 - 60': $ageGroupOfEldestMember="56 - 60";
  2307. break;
  2308. case '61 - 65': $ageGroupOfEldestMember="61 - 65";
  2309. break;
  2310. case '66 - 70': $ageGroupOfEldestMember="66 - 70";
  2311. break;
  2312. case '71 - 75': $ageGroupOfEldestMember="71 - 75";
  2313. break;
  2314. case '76 - 99': $ageGroupOfEldestMember="76 - 99";
  2315. break;
  2316. default: $ageGroupOfEldestMember="";
  2317. break;
  2318. }
  2319. $coverType="INDIVIDUAL";
  2320. if($ageGroupOfEldestMember==""){header("Location: "._SITEURL);exit;}else{}
  2321. if(@$sumInsured>0){
  2322. $sumInsured1=$INDIVIDUAL[@$sumInsured];
  2323. }
  2324. if($sumInsured1==""){header("Location: "._SITEURL);exit;}else{}
  2325. $numberOfAdult=0;
  2326. $numberOfChildren=0;
  2327. // $url1="&numberOfAdult=0&numberOfChildren=0";
  2328. //$url="Location: ".@$proposalURL."?productFamily=HEALTH&pCode=".@$productId1."&coverType=INDIVIDUAL&ageGroupOfEldestMember=".@$ageGroupOfEldestMember."&sumInsured=".@$sumInsured1."&tenure=".@$tenure.$url1."&mobileNum=".@$_SESSION['mobilephone'];
  2329. }else{
  2330. header("Location: "._SITEURL);exit;
  2331. }
  2332. ?><form name="PortalProposal" id="PortalProposal" method="post" action="<?=@$proposalURL;?>">
  2333. <input type="hidden" name="productFamily" value="HEALTH" />
  2334. <input type="hidden" name="pCode" value="<?=@$productId1;?>" />
  2335. <input type="hidden" name="coverType" value="<?=@$coverType;?>" />
  2336. <input type="hidden" name="ageGroupOfEldestMember" value="<?=@$ageGroupOfEldestMember;?>" />
  2337. <input type="hidden" name="sumInsured" value="<?=@$sumInsured1;?>" />
  2338. <input type="hidden" name="tenure" value="<?=@$tenure;?>" />
  2339. <input type="hidden" name="numberOfAdult" value="<?=@$numberOfAdult;?>" />
  2340. <input type="hidden" name="numberOfChildren" value="<?=@$numberOfChildren;?>" />
  2341. <input type="hidden" name="mobileNum" value="<?=@$mobileNumber;?>" />
  2342. <input type="hidden" name="quotationReferenceNum" value="<?=@$_SESSION['quotationReferenceNum'];?>" />
  2343. <input type="hidden" name="agentId" value="<?=@$_SESSION['agentId'];?>" />
  2344. </form>
  2345. <script>
  2346. document.PortalProposal.submit();
  2347. </script>
  2348. <?php
  2349. }
  2350. function xml2array($contents, $get_attributes=1, $priority = 'tag'){
  2351. if(!$contents) return array();
  2352. if(!function_exists('xml_parser_create')) {
  2353. //print "'xml_parser_create()' function not found!";
  2354. return array();
  2355. }
  2356. //Get the XML parser of PHP - PHP must have this module for the parser to work
  2357. $parser = xml_parser_create('');
  2358. xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
  2359. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  2360. xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  2361. xml_parse_into_struct($parser, trim($contents), $xml_values);
  2362. xml_parser_free($parser);
  2363. if(!$xml_values) return;//Hmm...
  2364. //Initializations
  2365. $xml_array = array();
  2366. $parents = array();
  2367. $opened_tags = array();
  2368. $arr = array();
  2369. $current = &$xml_array; //Refference
  2370. //Go through the tags.
  2371. $repeated_tag_index = array();//Multiple tags with same name will be turned into an array
  2372. foreach($xml_values as $data) {
  2373. unset($attributes,$value);//Remove existing values, or there will be trouble
  2374. //This command will extract these variables into the foreach scope
  2375. // tag(string), type(string), level(int), attributes(array).
  2376. extract($data);//We could use the array by itself, but this cooler.
  2377. $result = array();
  2378. $attributes_data = array();
  2379. if(isset($value)) {
  2380. if($priority == 'tag') $result = $value;
  2381. else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode
  2382. }
  2383. //Set the attributes too.
  2384. if(isset($attributes) and $get_attributes) {
  2385. foreach($attributes as $attr => $val) {
  2386. if($priority == 'tag') $attributes_data[$attr] = $val;
  2387. else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
  2388. }
  2389. }
  2390. //See tag status and do the needed.
  2391. if($type == "open") {//The starting of the tag '<tag>'
  2392. $parent[$level-1] = &$current;
  2393. if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
  2394. $current[$tag] = $result;
  2395. if($attributes_data) $current[$tag. '_attr'] = $attributes_data;
  2396. $repeated_tag_index[$tag.'_'.$level] = 1;
  2397. $current = &$current[$tag];
  2398. } else { //There was another element with the same tag name
  2399. if(isset($current[$tag][0])) {//If there is a 0th element it is already an array
  2400. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
  2401. $repeated_tag_index[$tag.'_'.$level]++;
  2402. } else {//This section will make the value an array if multiple tags with the same name appear together
  2403. $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array
  2404. $repeated_tag_index[$tag.'_'.$level] = 2;
  2405. if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
  2406. $current[$tag]['0_attr'] = $current[$tag.'_attr'];
  2407. unset($current[$tag.'_attr']);
  2408. }
  2409. }
  2410. $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
  2411. $current = &$current[$tag][$last_item_index];
  2412. }
  2413. } elseif($type == "complete") { //Tags that ends in 1 line '<tag />'
  2414. //See if the key is already taken.
  2415. if(!isset($current[$tag])) { //New Key
  2416. $current[$tag] = $result;
  2417. $repeated_tag_index[$tag.'_'.$level] = 1;
  2418. if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data;
  2419. } else { //If taken, put all things inside a list(array)
  2420. if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...
  2421. // ...push the new element into that array.
  2422. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
  2423. if($priority == 'tag' and $get_attributes and $attributes_data) {
  2424. $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
  2425. }
  2426. $repeated_tag_index[$tag.'_'.$level]++;
  2427. } else { //If it is not an array...
  2428. $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
  2429. $repeated_tag_index[$tag.'_'.$level] = 1;
  2430. if($priority == 'tag' and $get_attributes) {
  2431. if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
  2432. $current[$tag]['0_attr'] = $current[$tag.'_attr'];
  2433. unset($current[$tag.'_attr']);
  2434. }
  2435. if($attributes_data) {
  2436. $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
  2437. }
  2438. }
  2439. $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken
  2440. }
  2441. }
  2442. } elseif($type == 'close') { //End of tag '</tag>'
  2443. $current = &$parent[$level-1];
  2444. }
  2445. }
  2446. return($xml_array);
  2447. }
  2448. function subcategory_page_array($pageListArray1){
  2449. $m =0;
  2450. $dataArr=array();
  2451. if(is_array(@$pageListArray1['subcategory'][0]) ) {
  2452. $pageListArray = $pageListArray1['subcategory'];
  2453. for($i=0;$i<sizeof($pageListArray);$i++)
  2454. {
  2455. if(trim($pageListArray[$i]['isDeleted']['value'])=='no'){
  2456. $dataArr[$m]['subCategoryId'] = trim($pageListArray[$i]['subCategoryId']['value']);
  2457. $dataArr[$m]['categoryId'] =trim(@$pageListArray[$i]['categoryId']['value']);
  2458. $dataArr[$m]['subCategoryName'] = @$pageListArray[$i]['subCategoryName']['value'];
  2459. $dataArr[$m]['productCode'] = @$pageListArray[$i]['productCode']['value'];
  2460. $dataArr[$m]['description'] = @$pageListArray[$i]['description']['value'];
  2461. $dataArr[$m]['briefDescription'] = @$pageListArray[$i]['briefDescription']['value'];
  2462. $dataArr[$m]['metaTitle'] = @$pageListArray[$i]['metaTitle']['value'];
  2463. $dataArr[$m]['metaDescription'] = @$pageListArray[$i]['metaDescription']['value'];
  2464. $dataArr[$m]['metaKeywords'] = @$pageListArray[$i]['metaKeywords']['value'];
  2465. $dataArr[$m]['compare'] = @$pageListArray[$i]['compare']['value'];
  2466. $dataArr[$m]['exclusions'] =@$pageListArray[$i]['exclusions']['value'];
  2467. $dataArr[$m]['policyTerms'] =@$pageListArray[$i]['policyTerms']['value'];
  2468. $dataArr[$m]['agentpolicyTerms'] =@$pageListArray[$i]['agentpolicyTerms']['value'];
  2469. $dataArr[$m]['claim'] = @$pageListArray[$i]['claim']['value'];
  2470. $dataArr[$m]['logo'] = @$pageListArray[$i]['logo']['value'];
  2471. $dataArr[$m]['thumbnail'] = @$pageListArray[$i]['thumbnail']['value'];
  2472. $dataArr[$m]['isDeleted'] = trim($pageListArray[$i]['isDeleted']['value']);
  2473. $m++;
  2474. }
  2475. }
  2476. }else {
  2477. $pageListArray = @$pageListArray1['subcategory'];
  2478. if(trim($pageListArray['isDeleted']['value']) =='no') {
  2479. $dataArr[$m]['subCategoryId'] = trim($pageListArray['subCategoryId']['value']);
  2480. $dataArr[$m]['categoryId'] = trim($pageListArray['categoryId']['value']);
  2481. $dataArr[$m]['subCategoryName'] = $pageListArray['subCategoryName']['value'];
  2482. $dataArr[$m]['productCode'] = @$pageListArray['productCode']['value'];
  2483. $dataArr[$m]['description'] = $pageListArray['description']['value'];
  2484. $dataArr[$m]['briefDescription']= $pageListArray['briefDescription']['value'];
  2485. $dataArr[$m]['metaTitle'] = $pageListArray['metaTitle']['value'];
  2486. $dataArr[$m]['metaDescription'] = $pageListArray['metaDescription']['value'];
  2487. $dataArr[$m]['metaKeywords'] = $pageListArray['metaKeywords']['value'];
  2488. $dataArr[$m]['compare'] = $pageListArray['compare']['value'];
  2489. $dataArr[$m]['exclusions'] = $pageListArray['exclusions']['value'];
  2490. $dataArr[$m]['claim'] = $pageListArray['claim']['value'];
  2491. $dataArr[$m]['policyTerms'] =@$pageListArray['policyTerms']['value'];
  2492. $dataArr[$m]['agentpolicyTerms'] =@$pageListArray['agentpolicyTerms']['value'];
  2493. $dataArr[$m]['logo'] = @$pageListArray['logo']['value'];
  2494. $dataArr[$m]['thumbnail'] = @$pageListArray['thumbnail']['value'];
  2495. $dataArr[$m]['isDeleted'] = trim($pageListArray[$i]['isDeleted']['value']);
  2496. $m++;
  2497. }
  2498. }
  2499. //sort by
  2500. if (count ($dataArr) > 0) {
  2501. foreach ($dataArr as $key => $row) {
  2502. @$order_in_category[$key] = $row[0];//[0] is @$order_in_category
  2503. }
  2504. @array_multisort(@$order_in_category, SORT_ASC, $dataArr);
  2505. }
  2506. return $dataArr;
  2507. }
  2508. public function actiongetWebserviceLeadXMLResponse(){
  2509. $data='';
  2510. $leadURL=$_SERVER['DOCUMENT_ROOT']."/religarewebservices/data";
  2511. $r=0;
  2512. foreach(glob($leadURL . '/*request.xml') as $files){
  2513. $checkLeadExistorNot=Lead::model()->findByAttributes(array('fileName'=>$files));
  2514. if(count($checkLeadExistorNot)==0){
  2515. $data=file_get_contents($files);
  2516. $result=$this->xml2array($data);
  2517. $createdLeadDetails=$result['SOAP:Envelope']['SOAP:Body']['Createlead']['Lead'];
  2518. $OrganizationName=$result['SOAP:Envelope']['SOAP:Body']['Createlead']['OrganizationName'];
  2519. $type='Lead';
  2520. $leadsourceCode=$createdLeadDetails['leadsourcecode'];
  2521. $subject=$createdLeadDetails['subject'];
  2522. $firstname=$createdLeadDetails['firstname'];
  2523. $lastname=$createdLeadDetails['lastname'];
  2524. $emailaddress1=$createdLeadDetails['emailaddress1'];
  2525. $telephone1=$createdLeadDetails['telephone1'];
  2526. $mobilephone=$createdLeadDetails['mobilephone'];
  2527. $product=$createdLeadDetails['rhi_product'];
  2528. $suminsured=$createdLeadDetails['rhi_suminsured'];
  2529. $suminsured=(count($suminsured) > 0)?$suminsured:0;
  2530. $premium=$createdLeadDetails['rhi_premium'];
  2531. $premium=(count($premium) > 0)?$premium:0;
  2532. $quoteid=$createdLeadDetails['rhi_quoteid'];
  2533. $proposalid=$createdLeadDetails['rhi_proposalid'];
  2534. $leadstage=$createdLeadDetails['rhi_leadstage'];
  2535. $agentid=$createdLeadDetails['rhi_agentid'];
  2536. $noofyears=$createdLeadDetails['rhi_noofyears'];
  2537. $ProductMaster=ProductMaster::model()->findByAttributes(array('productName'=>$product));
  2538. $productId=$ProductMaster['productId'];
  2539. if(count($result) > 0){
  2540. //echo $files;
  2541. $model = new Lead;
  2542. $model->setAttributes(array(
  2543. 'name' => 'web services',
  2544. 'email' => '',
  2545. 'mobile' => $mobilephone,
  2546. 'productId' => $productId,
  2547. 'members' => 0,
  2548. 'si' => $suminsured,
  2549. 'premium' => $premium,
  2550. 'leadStageId' => '',
  2551. 'fileName' => addslashes($files),
  2552. 'status' => 'Active',
  2553. 'createdOn' => time(),
  2554. 'updatedOn' => time(),
  2555. 'updatedBy' => time(),
  2556. 'createdBy' => time(),
  2557. ));
  2558. //print_r($model);
  2559. $model->isNewRecord = true;
  2560. @$model->save(false);
  2561. } $r++;
  2562. }
  2563. }
  2564. $this->redirect(array('leads/lead_list'));
  2565. }
  2566. public function actionfresh_leads()
  2567. {
  2568. //$modelLead = Lead::model()->findAll("leadStatusId = '34' AND currentAllocatedId<1 ");
  2569. $this->render('fresh_lead_list');
  2570. }
  2571. public function actionviewAllTeams() {
  2572. if (!Yii::app()->request->isAjaxRequest){
  2573. }
  2574. else {
  2575. $this->renderPartial('/leads/partialAllTeamDetails');
  2576. Yii::app()->end();
  2577. }
  2578. }
  2579. public function actionViewLeadActivity() {
  2580. $followupId=@$_REQUEST['id'];
  2581. $model=new LeadFollowup;
  2582. $model=LeadFollowup::model()->findByPk($followupId);
  2583. if (!Yii::app()->request->isAjaxRequest){
  2584. // $this->render('yourView');
  2585. }
  2586. else {
  2587. $this->renderPartial('/leads/ViewLeadActivity',array('model'=>$model));
  2588. Yii::app()->end();
  2589. }
  2590. }
  2591. public function actionViewCalenderActs() {
  2592. //$cs = Yii::app()->getClientScript(); $cs->registerCoreScript('jquery');
  2593. $this->layout=false;
  2594. $startDate=@$_REQUEST['id'];
  2595. $model = LeadFollowup::model()->findAll(array("condition"=>"startDate = '".@$startDate."' AND userId = '".@$_SESSION['id']."' AND STATUS = 'Pending' AND (actionType = 'Meeting' OR actionType = 'Follow Up') ORDER BY hour DESC"));
  2596. if (!Yii::app()->request->isAjaxRequest){
  2597. $this->renderPartial('/leads/ViewCalenderActs',array('model'=>$model,'startDate'=>@$startDate));
  2598. }
  2599. else {
  2600. $this->renderPartial('/leads/ViewCalenderActs',array('model'=>$model,'startDate'=>@$startDate));
  2601. Yii::app()->end();
  2602. }
  2603. }
  2604. public function actionEditCalenderActivity() {
  2605. $this->layout=false;
  2606. $leadId=@$_REQUEST['leadId'];
  2607. $actionId=@$_REQUEST['actionId'];
  2608. $this->renderPartial('EditCalenderActivity',array('leadId'=>$leadId,'actionId'=>$actionId) ,false, true);
  2609. Yii::app()->end();
  2610. }
  2611. public function actiongetActionRes(){
  2612. $statusids = @$_POST['statusids'];
  2613. $model = new LeadStatus;
  2614. $model=LeadStatus::model()->findByPk($statusids);
  2615. echo $result = @$model['actionCompulsary'];
  2616. }
  2617. public function actioncip_lead_list()
  2618. {
  2619. //$model = new LeadStatus;
  2620. $this->render('contact_in_progress_lead_list');
  2621. }
  2622. public function actioncld_lead_list()
  2623. {
  2624. //$model = new Lead;
  2625. $this->render('cld_lead_list');
  2626. }
  2627. public function actionsearchCIP(){
  2628. if(Yii::app()->request->isAjaxRequest==1){
  2629. $models=new Lead();
  2630. $searchIDs =@$_REQUEST['searchIDs'];
  2631. if(isset($searchIDs) && !empty($searchIDs)){
  2632. $this->renderPartial('partialcip',array('searchTxt'=>$searchIDs,'type'=>'cip'));
  2633. }
  2634. } else {
  2635. $redirectUrl = Yii::app()->controller->id."/".$this->action->id;
  2636. $this->redirect("index.php?r=leads/cip_lead_list&pageSize=".@$_REQUEST['pageSize']);
  2637. }
  2638. }
  2639. public function actiondup_forthe_day_lead_list()
  2640. {
  2641. //$modelLead = new Lead;
  2642. $this->render('duplicate_forthe_daylead_list');
  2643. }
  2644. public function actionSearchArchiveLeads(){
  2645. $model = new Lead;
  2646. $teamId = @$_POST['Team']['teamId'];
  2647. $Leadname = @$_POST['Lead']['name'];
  2648. $Leadstatus = @$_POST['Lead']['status'];
  2649. $leadStage = @$_POST['Lead']['leadStage'];
  2650. $this->render('archive_leads',array('model'=>$model,'teamId'=>$teamId,'Leadname'=>$Leadname,'Leadstatus'=>$Leadstatus,'leadStage'=>$leadStage));
  2651. }
  2652. public function actionplc_lead_list()
  2653. {
  2654. //$model = new Lead;
  2655. $this->render('plc_lead_list');
  2656. }
  2657. public function getAgentIds($ws_agentid,$mobile){
  2658. $agentIds=Yii::app()->db->createCommand("select distinct ws_agentid from lead where mobile='".@$mobile."' and ws_agentid!='' order by leadId desc ")->queryAll();
  2659. if(count($agentIds) > 0) {
  2660. for($i=0;$i<count($agentIds);$i++){
  2661. $agentId[] = @$agentIds[$i]['ws_agentid'];
  2662. }
  2663. } else {
  2664. echo "";
  2665. }
  2666. if( count(@$agentId) > 1){
  2667. echo "<div class='linkUnderline' title='".implode(',',$agentId)."'><a href='#'>".$ws_agentid."</a></div>";
  2668. } else if( count(@$agentId) == 1) {
  2669. echo "<div title='".implode(',',@$agentId)."'><a href='#'>".$ws_agentid."</a></div>";
  2670. } else {
  2671. echo "";
  2672. }
  2673. //echo explode(',',$agentId);
  2674. }
  2675. }