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

/lms_debug/protected/controllers/LeadsController_17_nov_2014.php

https://gitlab.com/badelal143/lms_debug
PHP | 3431 lines | 2832 code | 318 blank | 281 comment | 521 complexity | 0ece98c313a62f12a06b6b44fce1961b MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  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. $parser = new CHtmlPurifier();
  155. if(isset($_POST['LeadFollowup'])){
  156. if(isset($_POST['LeadFollowup']['chkActionValid']) && @$_POST['LeadFollowup']['chkActionValid']==1){
  157. $res = $this->actionlead_followup(@$_POST['LeadFollowup'],$parser->purify(intval(@$_POST['Lead']['leadStatusId'])));
  158. $decodeRes = json_decode($res);
  159. if(@$decodeRes->status == 'success'){
  160. echo CJSON::encode(array(
  161. 'status'=>'success'
  162. ));
  163. } else {
  164. echo $res;
  165. }
  166. }
  167. }
  168. $leadFollDesc = @$_POST['LeadFollowup']['description'];
  169. // end of for follow ups
  170. $leadId = $parser->purify(intval(@$_GET['leadId']));
  171. $actionId = $parser->purify(intval(@$_REQUEST['actionId']));
  172. $actionmodel=LeadFollowup::model()->findByPk($actionId);
  173. $model = new Lead();
  174. $this->performAjaxValidation($model);
  175. $model->scenario = 'Lead';
  176. $managerMemberId = implode(",",$_SESSION['relationalManager']);
  177. $chkAllocatedLeads = $managerMemberId?Lead::model()->findAll(array("select"=>" leadId","condition"=>" leadStatusId != '26' AND leadStatusId != '25' AND currentAllocatedId IN (".@$managerMemberId.") ")):'0';
  178. $allocatedArr=array();
  179. foreach($chkAllocatedLeads as $key=>$value){
  180. $allocatedArr[]=$chkAllocatedLeads[$key]->leadId;
  181. }
  182. //print_r($allocatedArr);
  183. //die;
  184. /*if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin'){
  185. if(!in_array($leadId,$allocatedArr)){
  186. $this->redirect(array('leads/lead_list'));
  187. }
  188. }*/
  189. if(!empty($leadId)){
  190. $model=Lead::model()->findByPk($leadId);
  191. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  192. if(count($chkrecentlyViewed) == 0){
  193. $recentlyViewed = new recentlyViewed;
  194. $recentlyViewed->setAttributes(array(
  195. 'userId' => Yii::app()->session->get('id'),
  196. 'leadId' => $leadId,
  197. 'moduleId' => 0,
  198. 'updatedOn' => $_SESSION['id'],
  199. 'updatedBy' => $_SESSION['id'],
  200. ));
  201. $recentlyViewed->save(false);
  202. }
  203. }
  204. if(isset($_POST['Lead']))
  205. {
  206. if($_POST['LeadFollowup']['startDate']!='') {
  207. $finalLeadDesc = @$leadFollDesc;
  208. } else {
  209. $finalLeadDesc = @$_POST['Lead']['leadDescription'];
  210. }
  211. $model->setAttributes(array(
  212. 'updatedOn' => time(), //additional
  213. 'updatedBy' => $_SESSION['id'], //additional
  214. 'status' => 'Active', //additional //additional
  215. 'leadDescription' => @$finalLeadDesc, //additional //additional
  216. ));
  217. $prevLeadStatusId=$model->leadStatusId;
  218. foreach($_POST['Lead'] as $name=>$value)
  219. {
  220. if($model->leadStatusId==''){
  221. $model->leadStatusId=$model->leadStatusParentId;
  222. }
  223. if($model->email=='Email'){
  224. $model->email='';
  225. }
  226. if($model->name=='Name'){
  227. $model->name='';
  228. }
  229. if($model->address=='Address'){
  230. $model->address='';
  231. }
  232. if($model->ws_proposalid=='Proposal No.'){
  233. $model->ws_proposalid='';
  234. }
  235. if($model->children=="Children (Less than 25 Yrs)"){
  236. $model->children='';
  237. }
  238. if($model->ageGroup=="Age of eldest member"){
  239. $model->ageGroup='';
  240. }
  241. if($model->leadDescription=="Lead Description"){
  242. $model->leadDescription='';
  243. }
  244. if($model->leadStatusId==''){
  245. $model->leadStatusId=$prevLeadStatusId;
  246. }
  247. if(@$leadId!='' && $model->leadStatusId!='34' && @$model->leadStatusId!='35'){
  248. $model->isRead='yes';
  249. }
  250. if(is_array($value)){
  251. $value = '';
  252. } else {
  253. $value = $value;
  254. }
  255. $model->$name=$parser->purify($value);
  256. }
  257. if($model->leadStatusParentId=='1'){
  258. $model->salesClosedUpdatedOn=time();
  259. }
  260. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($model->leadSourceId);
  261. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  262. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  263. if(@$leadId!='' && $model->leadStatusId!='34'){
  264. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  265. }
  266. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  267. if($model->leadStatusId=='1'){
  268. $model->scenario = 'salesclosed';
  269. }
  270. if(count($chkStatusMandatoryOrNot) > 0){
  271. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  272. if($condMandatory == 'No'){
  273. if($model->validate(array('mobile'))){
  274. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  275. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  276. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  277. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  278. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  279. $modelHistory = new LeadHistory();
  280. $modelHistory->scenario = 'LeadHistory';
  281. $modelHistory->setAttributes(array(
  282. 'leadId' => @$leadId, //additional data you want to insert
  283. 'updatedOn' => time(), //additional
  284. 'updatedBy' => $_SESSION['id'], //additional
  285. 'status' => 'Active', //additional
  286. 'leadDescription' => @$finalLeadDesc,
  287. ));
  288. foreach($_POST['Lead'] as $name1=>$value1)
  289. {
  290. if($modelHistory->leadStatusId==''){
  291. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  292. }
  293. if(@$_POST['LeadFollowup']['description']=='Description'){
  294. $activitydesc = '';
  295. } else {
  296. $activitydesc = @$_POST['LeadFollowup']['description'];
  297. }
  298. $modelHistory->activityDescription=@$activitydesc;
  299. if($model->leadStatusId==''){
  300. $model->leadStatusId=2;
  301. }
  302. if($modelHistory->email=='Email'){
  303. $modelHistory->email='';
  304. }
  305. if($modelHistory->name=='Name'){
  306. $modelHistory->name='';
  307. }
  308. if($modelHistory->address=='Address'){
  309. $modelHistory->address='';
  310. }
  311. if($modelHistory->leadDescription=="Lead Description"){
  312. $modelHistory->leadDescription='';
  313. }
  314. if($modelHistory->children=="Children (Less than 25 Yrs)"){
  315. $modelHistory->children='';
  316. }
  317. if($modelHistory->ageGroup=="Age of eldest member"){
  318. $modelHistory->ageGroup='';
  319. }
  320. if(is_array($value1)){
  321. $value1 = '';
  322. } else {
  323. $value1 = $value1;
  324. }
  325. $modelHistory->$name1=$parser->purify($value1);
  326. }
  327. $model->save(false);
  328. $modelHistory->save();
  329. CJSON::encode(array(
  330. 'status'=>'success'
  331. ));
  332. Yii::app()->end();
  333. }
  334. }
  335. }
  336. $model->save();
  337. if($model->validate()){
  338. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  339. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  340. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  341. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  342. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  343. $modelHistory = new LeadHistory();
  344. $modelHistory->scenario = 'LeadHistory';
  345. $modelHistory->setAttributes(array(
  346. 'leadId' => @$leadId, //additional data you want to insert
  347. 'updatedOn' => time(), //additional
  348. 'updatedBy' => $_SESSION['id'], //additional
  349. 'status' => 'Active', //additional
  350. 'leadDescription' => @$finalLeadDesc,
  351. ));
  352. foreach($_POST['Lead'] as $name1=>$value1)
  353. {
  354. if($modelHistory->leadStatusId==''){
  355. $modelHistory->leadStatusId=$modelHistory->leadStatusParentId;
  356. }
  357. $modelHistory->activityDescription=@$_POST['LeadFollowup']['description'];
  358. if($model->leadStatusId==''){
  359. $model->leadStatusId=2;
  360. }
  361. if(is_array($value1)){
  362. $value1 = '';
  363. } else {
  364. $value1 = $value1;
  365. }
  366. $modelHistory->$name1=$parser->purify($value1);
  367. }
  368. $modelHistory->save();
  369. echo CJSON::encode(array(
  370. 'status'=>'success'
  371. ));
  372. Yii::app()->end();
  373. //Yii::app()->end();
  374. //die;
  375. //$this->redirect(array('leads/leads_details'));
  376. } else {
  377. @$error = CActiveForm::validate(@$model);
  378. if($error!='[]')
  379. echo @$error;
  380. Yii::app()->end();
  381. //$this->render('leads_details',array('model'=>$model));
  382. }
  383. } else {
  384. $this->render('leads_details',array('model'=>@$model,'actionmodel'=>@$actionmodel,'quotesmobile'=>@$model->mobile));
  385. }
  386. }
  387. protected function performAjaxValidation($models)
  388. {
  389. if(isset($_POST['ajax']) && $_POST['ajax']==='user-form')
  390. {
  391. echo CActiveForm::validate($models);
  392. Yii::app()->end();
  393. }
  394. }
  395. /**
  396. * This is the 'lead_list_allocator' action that is invoked
  397. * when an action is not explicitly requested by users.
  398. */
  399. public function actionlead_followup()
  400. {
  401. $actionId = @$_REQUEST['actionId'];
  402. $model = new LeadFollowup();
  403. $model->scenario = 'LeadFollowup';
  404. if(isset($actionId) && !empty($actionId)){
  405. $model=LeadFollowup::model()->findByPk($actionId);
  406. } else {
  407. }
  408. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  409. $model->scenario = 'LeadFollowupTask';
  410. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  411. $model->scenario = 'LeadFollowup';
  412. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  413. $model->scenario = 'LeadFollowup';
  414. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  415. $model->scenario = 'LeadFollowupNotes';
  416. }
  417. $parser = new CHtmlPurifier();
  418. $this->performAjaxValidation($model);
  419. if(isset($_POST['LeadFollowup']))
  420. {
  421. $userId = $_POST['LeadFollowup']['userId'];
  422. $followupstartdatewithtime = strtotime(@$_POST['LeadFollowup']['startDate'])+(@$_POST['LeadFollowup']['hour']*60*60)+(@$_POST['LeadFollowup']['minutes']*60);
  423. $model->setAttributes(array(
  424. 'createdOn' => time(), //additional data you want to insert
  425. 'updatedOn' => time(), //additional
  426. 'updatedBy' => @$userId, //additional
  427. 'createdBy' => @$userId, //additional
  428. 'status' => 'Pending', //additional
  429. ));
  430. foreach($_POST['LeadFollowup'] as $name=>$value)
  431. {
  432. if(is_array($value)){
  433. $value = '';
  434. } else {
  435. $value = $value;
  436. }
  437. $model->$name=$parser->purify($value);
  438. }
  439. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  440. $model->startDateWithTime=@$followupstartdatewithtime;
  441. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  442. $prefix=substr(time(),0,5);
  443. $folder = 'siteupload/';
  444. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  445. if($model->notesFile !='')
  446. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  447. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  448. }
  449. if(@$_POST['LeadFollowup']['startDate']!='') {
  450. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  451. $model->startDate=@$startDateVal;
  452. }
  453. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  454. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  455. $model->taskDueDate=@$taskDueDateVal;
  456. }
  457. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  458. $model->taskCompleted='yes';
  459. }
  460. if($model->validate()){
  461. $checkForSameDateExistsOrNot=LeadFollowup::model()->findAll(" leadId='".@$_POST['LeadFollowup']['leadId']."' and startDate <= '".$model->startDate."' and userId = '".@$userId."' and createdBy = '".@$userId."' ");
  462. if(count(@$checkForSameDateExistsOrNot) > 0){
  463. $update = Yii::app()->db->createCommand("UPDATE leadFollowup SET taskCompleted = 'yes',status = 'Completed' WHERE startDate <= '".$model->startDate."' and userId = '".@$userId."' and createdBy = '".@$userId."' and leadId='".@$_POST['LeadFollowup']['leadId']."' ")->execute();
  464. }
  465. $model->save();
  466. $leadId = $_POST['LeadFollowup']['leadId'];
  467. return 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. /**
  482. * This is the 'lead_list_allocator' action that is invoked
  483. * when an action is not explicitly requested by users.
  484. */
  485. public function actionlead_followupcalender()
  486. {
  487. $actionId = @$_REQUEST['actionId'];
  488. $model = new LeadFollowup();
  489. $model->scenario = 'LeadFollowup';
  490. if(isset($actionId) && !empty($actionId)){
  491. $model=LeadFollowup::model()->findByPk($actionId);
  492. } else {
  493. }
  494. if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Task'){
  495. $model->scenario = 'LeadFollowupTask';
  496. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Follow Up'){
  497. $model->scenario = 'LeadFollowup';
  498. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Meeting'){
  499. $model->scenario = 'LeadFollowup';
  500. }if(isset($_POST['LeadFollowup']['actionType']) && $_POST['LeadFollowup']['actionType']=='Notes'){
  501. $model->scenario = 'LeadFollowupNotes';
  502. }
  503. $this->performAjaxValidation($model);
  504. if(isset($_POST['LeadFollowup']))
  505. {
  506. $userId = $_POST['LeadFollowup']['userId'];
  507. $model->setAttributes(array(
  508. 'createdOn' => time(), //additional data you want to insert
  509. 'updatedOn' => time(), //additional
  510. 'updatedBy' => @$userId, //additional
  511. 'createdBy' => @$userId, //additional
  512. 'status' => 'Pending', //additional
  513. ));
  514. foreach($_POST['LeadFollowup'] as $name=>$value)
  515. {
  516. $model->$name=$value;
  517. }
  518. $model->leadStatusId=@$_POST['Lead']['leadStatusId'];;
  519. if(@$_POST['LeadFollowup']['actionType']=='Notes') {
  520. $prefix=substr(time(),0,5);
  521. $folder = 'siteupload/';
  522. $model->notesFile=CUploadedFile::getInstance($model,'notesFile');
  523. if($model->notesFile !='')
  524. $model->notesFile->saveAs($folder.$prefix.$model->notesFile);
  525. $model->notesFile=$prefix.CUploadedFile::getInstance($model,'notesFile');
  526. }
  527. if(@$_POST['LeadFollowup']['startDate']!='') {
  528. $startDateVal = strtotime($_POST['LeadFollowup']['startDate']);
  529. $model->startDate=@$startDateVal;
  530. }
  531. if(@$_POST['LeadFollowup']['taskDueDate']!='') {
  532. $taskDueDateVal = strtotime($_POST['LeadFollowup']['taskDueDate']);
  533. $model->taskDueDate=@$taskDueDateVal;
  534. }
  535. if(@$_POST['LeadFollowup']['taskCompleted']!='') {
  536. $model->taskCompleted='yes';
  537. }
  538. if($model->validate()){
  539. $model->save();
  540. $leadId = $_POST['LeadFollowup']['leadId'];
  541. echo CJSON::encode(array(
  542. 'status'=>'success'
  543. ));
  544. Yii::app()->end();
  545. } else {
  546. $error = CActiveForm::validate($model);
  547. if($error!='[]')
  548. return $error;
  549. Yii::app()->end();
  550. }
  551. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  552. }
  553. $this->redirect(array('leads/lead_list'));
  554. }
  555. public function actionlead_contacts()
  556. {
  557. // renders the view file 'protected/views/site/index.php'
  558. // using the default layout 'protected/views/layouts/main.php'
  559. $model = new LeadContacts();
  560. $model->scenario = 'LeadContacts';
  561. $this->performAjaxValidation($model);
  562. if(!empty($_GET['contactId']))
  563. {
  564. $leadContactId=$_GET['leadContactId'];
  565. $model=LeadContacts::model()->findByPk($leadContactId);
  566. }
  567. if(!empty($_POST['LeadContacts']['leadContactId']))
  568. {
  569. $leadContactId=$_POST['LeadContacts']['leadContactId'];
  570. $model=LeadContacts::model()->findByPk($leadContactId);
  571. }
  572. if(isset($_POST['LeadContacts']))
  573. {
  574. $userId = $_POST['LeadContacts']['userId'];
  575. $leadId = $_POST['LeadContacts']['leadId'];
  576. $model->setAttributes(array(
  577. 'createdOn' => time(), //additional data you want to insert
  578. 'updatedOn' => time(), //additional
  579. 'updatedBy' => @$userId, //additional
  580. 'createdBy' => @$userId, //additional
  581. 'status' => 'Active', //additional
  582. ));
  583. foreach($_POST['LeadContacts'] as $name=>$value)
  584. {
  585. $model->$name=$value;
  586. }
  587. if($model->validate()){
  588. $model->save();
  589. echo CJSON::encode(array(
  590. 'status'=>'success'
  591. ));
  592. Yii::app()->end();
  593. } else {
  594. $error = CActiveForm::validate($model);
  595. if($error!='[]')
  596. echo $error;
  597. Yii::app()->end();
  598. }
  599. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  600. }
  601. $this->redirect(array('leads/lead_list'));
  602. }
  603. public function actionChangeContactStatus()
  604. {
  605. $Id=$_REQUEST['contactId'];
  606. $leadId=$_REQUEST['leadId'];
  607. $status=$_REQUEST['status'];
  608. if(isset($status)&&($status=='Inactive')){
  609. $status="Active";
  610. } else {
  611. $status="Inactive";
  612. }
  613. if(!empty($Id))
  614. {
  615. $model=LeadContacts::model()->findByPk($Id);
  616. }
  617. else
  618. {
  619. $model = LeadContacts::model()->findAll();
  620. }
  621. $model->status=$status;
  622. $model->save();
  623. $this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  624. }
  625. /**
  626. * This is the 'roles' action that is invoked
  627. * when an action is not explicitly requested by users.
  628. */
  629. public function actioncreate_lead()
  630. {
  631. $model=new Lead();
  632. $model->scenario = 'Lead';
  633. if(!empty($_GET['leadId']))
  634. {
  635. $leadId=$_GET['leadId'];
  636. $model=Lead::model()->findByPk($leadId);
  637. $chkrecentlyViewed=recentlyViewed::model()->findByAttributes(array('leadId'=>$leadId,'userId'=>Yii::app()->session->get('id')));
  638. if(count($chkrecentlyViewed) == 0){
  639. $recentlyViewed = new recentlyViewed;
  640. $recentlyViewed->setAttributes(array(
  641. 'userId' => Yii::app()->session->get('id'),
  642. 'leadId' => $leadId,
  643. 'moduleId' => 0,
  644. 'createdOn' => time(),
  645. 'updatedOn' => time(),
  646. 'updatedBy' => time(),
  647. 'createdBy' => time(),
  648. ));
  649. $recentlyViewed->save(false);
  650. }
  651. }
  652. if(!empty($_POST['Lead']['leadId']))
  653. {
  654. $leadId=$_POST['Lead']['leadId'];
  655. $model=Lead::model()->findByPk($leadId);
  656. }
  657. if(isset($_POST['Lead']))
  658. {
  659. $model->setAttributes(array(
  660. 'createdOn' => time(), //additional data you want to insert
  661. 'updatedOn' => time(), //additional
  662. 'updatedBy' => Yii::app()->session->get('id'), //additional
  663. 'createdBy' => Yii::app()->session->get('id'),
  664. ));
  665. foreach($_POST['Lead'] as $name=>$value)
  666. {
  667. $model->$name=$value;
  668. if($model->leadStatusId==''){
  669. $model->leadStatusId=$model->leadStatusParentId;
  670. }
  671. if($model->leadStatusId==''){
  672. $model->leadStatusId=34;
  673. }
  674. if($model->mobile=='Mobile*'){
  675. $model->mobile='';
  676. }
  677. if($model->email=='Email'){
  678. $model->email='';
  679. }
  680. if($model->name=='Name'){
  681. $model->name='';
  682. }
  683. if($model->address=='Address'){
  684. $model->address='';
  685. }
  686. if($model->children=="Children (Less than 25 Yrs)"){
  687. $model->children='';
  688. }
  689. if($model->ageGroup=="Age of eldest member"){
  690. $model->ageGroup='';
  691. }
  692. }
  693. if($model->leadStatusParentId=='1'){
  694. $model->salesClosedUpdatedOn=time();
  695. }
  696. if($model->leadSourceId=='' or empty($model->leadSourceId)){
  697. $model->leadSourceId = '2';
  698. }
  699. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($model->leadSourceId);
  700. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  701. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  702. if(Yii::app()->session->get('isAllocator')!='yes' and Yii::app()->session->get('type')!='superadmin') {
  703. @$model->leadStatusId=35;
  704. @$model->currentAllocatedId=Yii::app()->session->get('id');
  705. }
  706. if(@$leadId!='' && $model->leadStatusId!='34'){
  707. $update = Yii::app()->db->createCommand("update `lead` set `isRead`='yes' where `leadId`='$leadId' and currentAllocatedId > 0")->query();
  708. }
  709. if(@$_POST['Lead']['emailOptOut']=='on') { $model->emailOptOut='Y'; } else { $model->emailOptOut='N'; }
  710. if(@$_POST['Lead']['mobileOptOut']=='on') { $model->mobileOptOut='Y'; } else { $model->mobileOptOut='N'; }
  711. if(@$_POST['Lead']['isJunk']=='on') { $model->isJunk='yes'; } else { $model->isJunk='no'; }
  712. if(@$_POST['Lead']['isDuplicate']=='on') { $model->isDuplicate='yes'; } else { $model->isDuplicate='no'; }
  713. if(@$_POST['Lead']['status']=='on') { $model->status='Close'; } else { $model->status='Active'; }
  714. $chkStatusMandatoryOrNot = leadStatus::model()->findByAttributes(array('leadStatusId'=>$model->leadStatusId));
  715. if(count($chkStatusMandatoryOrNot) > 0){
  716. $condMandatory = $chkStatusMandatoryOrNot['compulsary'];
  717. if($condMandatory == 'No'){
  718. if($model->validate(array('mobile'))){
  719. $mobileNumber = @$_POST['Lead']['mobile'];
  720. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  721. if(empty($checkJunkNumber)){
  722. $beforethreemonth = time()-7776000;
  723. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  724. if(empty($checkDuplicateNumber)){
  725. $model->save(false);
  726. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  727. } else {
  728. $duplicateLeadId = $checkDuplicateNumber->leadId;
  729. $model->leadStatusId='10';
  730. $model->duplicateLeadId=@$duplicateLeadId;
  731. $model->currentAllocatedId=$checkDuplicateNumber->currentAllocatedId;
  732. $model->save(false);
  733. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  734. }
  735. } else {
  736. $model->leadStatusId='36';
  737. $model->save(false);
  738. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  739. }
  740. $this->redirect(array('leads/lead_list'));
  741. // $model->save(false);
  742. // $this->redirect(array('leads/lead_list'));
  743. }
  744. }
  745. }
  746. if($model->leadStatusId==36){
  747. $model->save(false);
  748. $this->redirect(array('leads/lead_list'));
  749. } else {
  750. if($model->validate()){
  751. $mobileNumber = $_POST['Lead']['mobile'];
  752. $checkJunkNumber = JunkNumbersMaster::model()->find('junkLeadNumber = "'.@$mobileNumber.'"');
  753. if(empty($checkJunkNumber)){
  754. $beforethreemonth = time()-7776000;
  755. $checkDuplicateNumber = Lead::model()->find('mobile = "'.@$mobileNumber.'" AND createdOn > "'.@$beforethreemonth.'" AND status = "Active" AND leadId != "'.@$leadId.'" ');
  756. if(empty($checkDuplicateNumber)){
  757. $model->save();
  758. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  759. } else {
  760. $duplicateLeadId = $checkDuplicateNumber->leadId;
  761. $model->leadStatusId='10';
  762. $model->duplicateLeadId=@$duplicateLeadId;
  763. $model->save();
  764. Yii::app()->user->setFlash('lead_msg_success','Successfully Inserted');
  765. }
  766. } else {
  767. $model->leadStatusId='36';
  768. $model->save();
  769. Yii::app()->user->setFlash('lead_msg_success','Junk Lead');
  770. }
  771. $this->redirect(array('leads/lead_list'));
  772. } else {
  773. $this->render('create_lead',array('model'=>$model));
  774. }
  775. }
  776. } else {
  777. $this->render('create_lead',array('model'=>$model));
  778. }
  779. }
  780. public function actionAllocateLeads(){
  781. $Id = $_REQUEST['userids'];
  782. $teamId = @$_REQUEST['Team']['teamId'];
  783. $userId = $_REQUEST['Team']['teamMemberId'];
  784. $updatedBy = @$_SESSION['id'];
  785. $updatedOn = time();
  786. $teamIdString = '';
  787. if($teamId)
  788. {
  789. $teamIdString = ',teamId = ' . $teamId . ', ';
  790. }
  791. foreach($Id as $key => $value)
  792. {
  793. $commonQueryString = ", updatedBy = $updatedBy, updatedOn = $updatedOn where leadId = $value";
  794. $updateLead = "update lead set currentAllocatedId = $userId, leadStatusId = 35, currentAllocatedDate = $updatedOn $commonQueryString";
  795. Yii::app()->db->createCommand($updateLead)->execute();
  796. }
  797. $red = @$_REQUEST['red'];
  798. if($this->action->id=='AllocateLeads' && $red == 1)
  799. {
  800. $this->redirect(array('leads/lead_list'));
  801. }
  802. $this->redirect(array('leads/fresh_leads'));
  803. }
  804. public function actionAllocateLeadsRES()
  805. {
  806. $Id = $_REQUEST['userids'];
  807. $teamId = @$_REQUEST['Team']['teamId'];
  808. $userId = $_REQUEST['Team']['teamMemberId'];
  809. $updatedBy = @$_SESSION['id'];
  810. foreach($Id as $key=>$value){
  811. $model = new AllocatedLeads();
  812. $model->scenario = 'AllocatedLeads';
  813. $model->setAttributes(array(
  814. 'currentAllocatedDate' => time(), //additional data you want to insert
  815. 'createdOn' => time(), //additional data you want to insert
  816. 'updatedOn' => time(), //additional
  817. 'updatedBy' => @$updatedBy, //additional
  818. 'createdBy' => @$updatedBy, //additional
  819. 'leadStatusId' => '35', //additional //additional
  820. ));
  821. $leadId = @$value;
  822. $model->leadId = @$value;
  823. $model->userId = @$userId;
  824. $model->teamId = @$teamId;
  825. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  826. $model->allocatedId = null;
  827. $model->isNewRecord = true;
  828. $model->save();
  829. $model=new Lead();
  830. $model->scenario = 'Lead';
  831. $updatedOn = time();
  832. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  833. }
  834. $red = @$_REQUEST['red'];
  835. if($this->action->id=='AllocateLeads' && $red == 1) {
  836. $this->redirect(array('leads/lead_list'));
  837. } else {
  838. $this->redirect(array('leads/fresh_leads'));
  839. }
  840. //$this->redirect(array('leads/lead_list'));
  841. }
  842. /**
  843. * This is the 'lead_list_allocator' action that is invoked
  844. * when an action is not explicitly requested by users.
  845. */
  846. public function actionlead_assign()
  847. {
  848. $model = new Lead();
  849. $model->scenario = 'Lead';
  850. $leadId = $_REQUEST['AssignLead']['leadId'];
  851. $userId = $_REQUEST['AssignLead']['userId'];
  852. $assign = $_REQUEST['AssignLead']['assign'];
  853. if($leadId!='') {
  854. $updatedOn = time();
  855. $chkleadStatus = Lead::model()->findByPk($leadId);
  856. $existsOrNot = $chkleadStatus['leadStatusId'];
  857. $leadStatusIdUpdate = $existsOrNot?$existsOrNot:'34';
  858. if($leadStatusIdUpdate == 34){
  859. $leadStatusIdUpdate = 35;
  860. } else {
  861. $leadStatusIdUpdate = $leadStatusIdUpdate;
  862. }
  863. if($assign=='open') {
  864. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>'','status'=>'Active','leadStatusId'=>34,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>''));
  865. } elseif($assign=='self'){
  866. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$userId,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  867. } else {
  868. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$assign,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  869. }
  870. echo CJSON::encode(array(
  871. 'status'=>'success'
  872. ));
  873. Yii::app()->end();
  874. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  875. } else {
  876. $this->redirect(array('leads/lead_list'));
  877. }
  878. }
  879. /**
  880. * This is the 'roles' action that is invoked
  881. * when an action is not explicitly requested by users.
  882. */
  883. public function actionarchive_leads()
  884. {
  885. // renders the view file 'protected/views/site/index.php'
  886. // using the default layout 'protected/views/layouts/main.php'
  887. $model=new Lead();
  888. //$model=Lead::model()->findAll();
  889. $this->render('archive_leads',array('model'=>$model));
  890. }
  891. /**
  892. * This is the 'roles' action that is invoked
  893. * when an action is not explicitly requested by users.
  894. */
  895. public function actionbulk_import_leads()
  896. {
  897. // renders the view file 'protected/views/site/index.php'
  898. // using the default layout 'protected/views/layouts/main.php'
  899. $model=new Lead();
  900. $this->render('bulk_import_lead',array('model'=>$model));
  901. }
  902. /**
  903. * This is the 'roles' action that is invoked
  904. * when an action is not explicitly requested by users.
  905. */
  906. public function actionjunk_leads()
  907. {
  908. // renders the view file 'protected/views/site/index.php'
  909. // using the default layout 'protected/views/layouts/main.php'
  910. $this->render('junk_leads');
  911. }
  912. /**
  913. * This is the 'module master' action that is invoked
  914. * when an action is not explicitly requested by users.
  915. */
  916. public function actionmodule_master()
  917. {
  918. // renders the view file 'protected/views/site/index.php'
  919. // using the default layout 'protected/views/layouts/main.php'
  920. $model=new ModuleMaster();
  921. $model->scenario = 'ModuleMaster';
  922. if(!empty($_GET['moduleId']))
  923. {
  924. $moduleId=$_GET['moduleId'];
  925. $model=ModuleMaster::model()->findByPk($moduleId);
  926. }
  927. if(!empty($_POST['ModuleMaster']['moduleId']))
  928. {
  929. $moduleId=$_POST['ModuleMaster']['moduleId'];
  930. $model=ModuleMaster::model()->findByPk($moduleId);
  931. }
  932. if(isset($_POST['ModuleMaster']))
  933. {
  934. $model->setAttributes(array(
  935. 'createdOn' => time(), //additional data you want to insert
  936. 'updatedOn' => time(), //additional
  937. 'updatedBy' => time(), //additional
  938. 'createdBy' => time(),
  939. 'status' => 'Activated', //additional //additional
  940. ));
  941. foreach($_POST['ModuleMaster'] as $name=>$value)
  942. {
  943. $model->$name=$value;
  944. }
  945. if($model->validate()){
  946. $model->save();
  947. $model2=ModuleMaster::model()->findAll();
  948. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  949. Yii::app()->user->setFlash('module_master_msg_success','Successfully Inserted');
  950. } else {
  951. Yii::app()->user->setFlash('module_master_msg_error','Please check. error occured');
  952. $this->render('module_master',array('model'=>$model));
  953. }
  954. } else {
  955. $model2=ModuleMaster::model()->findAll();
  956. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  957. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  958. }
  959. }
  960. /**
  961. * This is the action to handle external exceptions.
  962. */
  963. public function actionError()
  964. {
  965. if($error=Yii::app()->errorHandler->error)
  966. {
  967. if(Yii::app()->request->isAjaxRequest)
  968. echo $error['message'];
  969. else
  970. $this->render('error', $error);
  971. }
  972. }
  973. /**
  974. * Displays the contact page
  975. */
  976. public function actionContact()
  977. {
  978. $model=new ContactForm;
  979. if(isset($_POST['ContactForm']))
  980. {
  981. $model->attributes=$_POST['ContactForm'];
  982. if($model->validate())
  983. {
  984. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  985. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  986. $headers="From: $name <{$model->email}>\r\n".
  987. "Reply-To: {$model->email}\r\n".
  988. "MIME-Version: 1.0\r\n".
  989. "Content-type: text/plain; charset=UTF-8";
  990. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  991. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  992. $this->refresh();
  993. }
  994. }
  995. $this->render('contact',array('model'=>$model));
  996. }
  997. /**
  998. * Displays the login page
  999. */
  1000. public function actionLogin()
  1001. {
  1002. $model=new User;
  1003. // if it is ajax validation request
  1004. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  1005. {
  1006. echo CActiveForm::validate($model);
  1007. Yii::app()->end();
  1008. }
  1009. // collect user input data
  1010. if(isset($_POST['User']))
  1011. {
  1012. $model->attributes=$_POST['User'];
  1013. // validate user input and redirect to the previous page if valid
  1014. if($model->validate() && $model->login()){
  1015. $this->redirect(array('masters/dashboard'));
  1016. } else {
  1017. $this->redirect(Yii::app()->user->returnUrl);
  1018. }
  1019. }
  1020. // display the login form
  1021. $this->render('login',array('model'=>$model));
  1022. }
  1023. /**
  1024. * Logs out the current user and redirect to homepage.
  1025. */
  1026. public function actionLogout()
  1027. {
  1028. setcookie ('PHPSESSID', '', time(), '/', '', 0, 0); // Destroy the cookie.
  1029. Yii::app()->user->logout();
  1030. $this->redirect(Yii::app()->homeUrl);
  1031. }
  1032. public function getPageType()
  1033. {
  1034. return "Leads";
  1035. }
  1036. public function init(){
  1037. $obj =new RecentlyViewedController(); // preparing object
  1038. $data=$obj->actionUserRoleAccess();
  1039. $moduleArray=array();
  1040. if(Yii::app()->session->get('type')=='superadmin'){
  1041. $moduleArray['read']='yes';
  1042. $moduleArray['write']='yes';
  1043. $moduleArray['delete']='yes';
  1044. }else{
  1045. foreach($data as $key=>$value){
  1046. if($data[$key]->modules->moduleName=='Leads'){
  1047. $moduleArray['moduleName']=$data[$key]->modules->moduleName;
  1048. $moduleArray['read']=$data[$key]->read;
  1049. $moduleArray['write']=$data[$key]->write;
  1050. $moduleArray['delete']=$data[$key]->delete;
  1051. }
  1052. }
  1053. }
  1054. return $moduleArray;
  1055. }
  1056. public function getNameFromNumber($num) {
  1057. $numeric = $num % 26;
  1058. $letter = chr(65 + $numeric);
  1059. $num2 = intval($num / 26);
  1060. if ($num2 > 0) {
  1061. return getNameFromNumber($num2 - 1) . $letter;
  1062. } else {
  1063. return $letter;
  1064. }
  1065. }
  1066. /*function actionexportArchiveList()
  1067. {
  1068. // generate a resultset
  1069. $model=new User;
  1070. $model=User::model()->findAll();
  1071. // render data to xlsx format and echo resultant file back to browser.
  1072. ExcelExporter::sendAsXLS($model, true, 'closedLeads.xls');
  1073. }*/
  1074. public function actionDownloadLeadTemp(){
  1075. Yii::import('ext.phpexcel.XPHPExcel');
  1076. $objPHPExcel= XPHPExcel::createPHPExcel();
  1077. $objPHPExcel->getProperties()->setCreator("LeadTemplate")
  1078. ->setLastModifiedBy("LeadTemplate")
  1079. ->setTitle("LeadTemplate")
  1080. ->setSubject("LeadTemplate")
  1081. ->setDescription("LeadTemplate.")
  1082. ->setKeywords("LeadTemplate")
  1083. ->setCategory("LeadTemplate");
  1084. //echo $total_excelColumns=$this->getNameFromNumber(4);
  1085. $total_excelColumns='I';
  1086. // Rename worksheet
  1087. $objPHPExcel->getActiveSheet()->setTitle('ClosedLeads');
  1088. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1089. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1090. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
  1091. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1092. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1093. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1094. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1095. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1096. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1097. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1098. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  1099. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1100. array(
  1101. 'font' => array(
  1102. 'name' => 'Times New Roman',
  1103. 'bold' => true,
  1104. 'italic' => false,
  1105. 'size' => 12
  1106. ),
  1107. 'borders' => array(
  1108. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1109. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1110. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1111. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1112. ),
  1113. 'alignment' => array(
  1114. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1115. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1116. 'wrap' => true
  1117. )
  1118. ),
  1119. 'A1:'.$total_excelColumns.'1'
  1120. );
  1121. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1122. // Add some data
  1123. $objPHPExcel->setActiveSheetIndex(0)
  1124. ->setCellValue('A1', 'Name')
  1125. ->setCellValue('B1', 'City')
  1126. ->setCellValue('C1', 'Email')
  1127. ->setCellValue('D1', 'Mobile')
  1128. ->setCellValue('E1', 'Suminsured')
  1129. ->setCellValue('F1', 'Age')
  1130. ->setCellValue('G1', 'No. Of Members')
  1131. ->setCellValue('H1', 'Date on submit')
  1132. ->setCellValue('I1', 'Lead Source');
  1133. // Miscellaneous glyphs, UTF-8
  1134. $objPHPExcel->setActiveSheetIndex(0)
  1135. ->setCellValue('A2', 'Lead Name')
  1136. ->setCellValue('B2', 'city')
  1137. ->setCellValue('C2', 'test@yesk.com')
  1138. ->setCellValue('D2', '9999999999')
  1139. ->setCellValue('E2', '56')
  1140. ->setCellValue('F2', '23')
  1141. ->setCellValue('G2', 'test')
  1142. ->setCellValue('H2', '07-Sep-2013')
  1143. ->setCellValue('I2', 'test');
  1144. //To create new sheet in current file
  1145. /*$objPHPExcel->createSheet(1);
  1146. $objPHPExcel->setActiveSheetIndex(1);
  1147. $objPHPExcel->getActiveSheet()->setTitle('Title');
  1148. */
  1149. // Redirect output to a client’s web browser (Excel5)
  1150. header('Content-Type: application/vnd.ms-excel');
  1151. header('Content-Disposition: attachment;filename="LeadTemplates.xls"');
  1152. header('Cache-Control: max-age=0');
  1153. // If you're serving to IE 9, then the following may be needed
  1154. header('Cache-Control: max-age=1');
  1155. // If you're serving to IE over SSL, then the following may be needed
  1156. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  1157. header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
  1158. header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
  1159. header ('Pragma: public'); // HTTP/1.0
  1160. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1161. $objWriter->save('php://output');
  1162. Yii::app()->end();
  1163. }
  1164. public function actionImportLeadTemplate(){
  1165. $model=new lead();
  1166. $data='';
  1167. $final_arr=@$_POST['final_arr']?@$_POST['final_arr']:'';
  1168. if(isset($_POST['ImportLeads']) && empty($final_arr) && !empty($_FILES['Lead']['name']['import'])){
  1169. Yii::import('ext.phpexcelreader.JPhpExcelReader');
  1170. $model->attributes='import';
  1171. $model->import=CUploadedFile::getInstance($model,'import');
  1172. $prefix=substr(time(),0,5);
  1173. $folder = '/tempdata';
  1174. $model->import->saveAs($folder.$prefix.$model->import);
  1175. $data=new JPhpExcelReader($folder.$prefix.$model->import);
  1176. //$this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1177. //$this->redirect(Yii::app()->createUrl('leads/bulk_import_leads'),array('data'=>$data,'model'=>$model));
  1178. $this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1179. }
  1180. if(isset($_POST['ImportLeads']) && !empty($final_arr) && isset($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1181. $final_arr = unserialize(urldecode($_POST["final_arr"]));
  1182. $dateTime=time();
  1183. /*echo '<pre>';
  1184. print_r($final_arr);*/
  1185. for($i=0;$i<sizeof($final_arr);$i++)
  1186. {
  1187. $leadStatusId = '0';
  1188. $duplicateLeadId = '0';
  1189. $currentAllocatedId = '0';
  1190. $junkNumberQuery = Yii::app()->db->createCommand("SELECT `junkLeadNumberId` FROM `junkLeadNumberMaster` WHERE `junkLeadNumber` = '".@$final_arr[$i]['mobile']."' ")->queryAll();
  1191. $junkNumberResult = $junkNumberQuery;
  1192. $fetchAgentDetails=LeadSourceMaster::model()->findByPk($final_arr[$i]['leadSourceId']);
  1193. //$duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' ")->queryAll();(Original, changed below by Baljeet)
  1194. $duplicateQuery = Yii::app()->db->createCommand("SELECT `leadId`,`currentAllocatedId` FROM `lead` WHERE `mobile`= '".@$final_arr[$i]['mobile']."' order by leadId ASC LIMIT 1")->queryAll();
  1195. $duplicateResult = ($duplicateQuery);
  1196. //echo '<br>duplicateResult----------'.count($duplicateResult);
  1197. if(count($junkNumberResult) > 0){
  1198. $leadStatusId = '36';
  1199. $duplicateLeadId = '';
  1200. $currentAllocatedId = '';
  1201. } elseif(count($duplicateResult)>0){
  1202. $leadStatusId = '10';
  1203. $duplicateLeadId = @$duplicateResult[0]['leadId'];
  1204. $currentAllocatedId = @$duplicateResult[0]['currentAllocatedId']; //added by baljeet
  1205. } else {
  1206. $leadStatusId = '34';
  1207. $duplicateLeadId = '';
  1208. $currentAllocatedId = '';
  1209. }
  1210. /*echo '<br>leadStatusId---'.$leadStatusId;
  1211. echo '<br>duplicateLeadId---'.$duplicateLeadId;
  1212. echo '<br>currentAllocatedId---'.$currentAllocatedId;*/
  1213. $model=new lead();
  1214. $model->name=$final_arr[$i]['name'];
  1215. $model->cityId=$final_arr[$i]['cityId'];
  1216. $model->email=$final_arr[$i]['email'];
  1217. $model->mobile=$final_arr[$i]['mobile'];
  1218. $model->si=$final_arr[$i]['suminsured'];
  1219. $model->age=$final_arr[$i]['age'];
  1220. $model->members=$final_arr[$i]['noofmembers'];
  1221. $model->dateonSubmit=$final_arr[$i]['dateonsubmit'];
  1222. $model->leadSourceId=$final_arr[$i]['leadSourceId'];
  1223. $model->leadStatusId=$leadStatusId;
  1224. $model->duplicateLeadId=@$duplicateLeadId;
  1225. $model->currentAllocatedId=@$currentAllocatedId;
  1226. $model->productId='1';
  1227. $model->status='Active';
  1228. $model->createdOn=$dateTime;
  1229. $model->createdBy=Yii::app()->session->get('id');
  1230. $model->updatedOn=$dateTime;
  1231. $model->updatedBy=Yii::app()->session->get('id');
  1232. $model->isBulkImport='YES';
  1233. $model->agentId = @$fetchAgentDetails->leadSourceCode;
  1234. $model->ws_agentid = @$fetchAgentDetails->leadSourceCode;
  1235. $model->isNewRecord = true;
  1236. $model->save(false);
  1237. }
  1238. $this->redirect(array('leads/lead_list'));
  1239. }
  1240. if(isset($_POST['ImportLeads']) && empty($final_arr) && empty($_FILES['Lead']['name']['import'])){
  1241. $model->validate();
  1242. $this->render('bulk_imp…

Large files files are truncated, but you can click here to view the full file