PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/lms_debug/protected/controllers/LeadsController_11dec2014.php

https://gitlab.com/badelal143/lms_debug
PHP | 3727 lines | 3051 code | 372 blank | 304 comment | 554 complexity | b2aaec71b70908335013c40e0a8879c4 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. {
  782. $Id = $_REQUEST['userids'];
  783. $teamId = @$_REQUEST['Team']['teamId'];
  784. $userId = $_REQUEST['Team']['teamMemberId'];
  785. $updatedBy = @$_SESSION['id'];
  786. $updatedOn = time();
  787. $teamIdString = '';
  788. if($teamId)
  789. {
  790. $teamIdString = ',teamId = ' . $teamId . ', ';
  791. }
  792. foreach($Id as $key => $value)
  793. {
  794. $commonQueryString = ", updatedBy = $updatedBy, updatedOn = $updatedOn where leadId = $value";
  795. $updateLead = "update lead set currentAllocatedId = $userId, leadStatusId = 35, currentAllocatedDate = $updatedOn $commonQueryString";
  796. Yii::app()->db->createCommand($updateLead)->execute();
  797. }
  798. $red = @$_REQUEST['red'];
  799. if($this->action->id=='AllocateLeads' && $red == 1)
  800. {
  801. $this->redirect(array('leads/lead_list'));
  802. }
  803. $this->redirect(array('leads/fresh_leads'));
  804. }
  805. public function actionAllocateLeads_17nov2014()
  806. {
  807. $Id = $_REQUEST['userids'];
  808. $teamId = @$_REQUEST['Team']['teamId'];
  809. $userId = $_REQUEST['Team']['teamMemberId'];
  810. $updatedBy = @$_SESSION['id'];
  811. foreach($Id as $key=>$value){
  812. $model = new AllocatedLeads();
  813. $model->scenario = 'AllocatedLeads';
  814. $model->setAttributes(array(
  815. 'currentAllocatedDate' => time(), //additional data you want to insert
  816. //'createdOn' => time(), //additional data you want to insert
  817. 'updatedOn' => time(), //additional
  818. 'updatedBy' => @$updatedBy, //additional
  819. 'createdBy' => @$updatedBy, //additional
  820. 'leadStatusId' => '35', //additional //additional
  821. ));
  822. $leadId = @$value;
  823. $model->leadId = @$value;
  824. $model->userId = @$userId;
  825. $model->teamId = @$teamId;
  826. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  827. $model->allocatedId = null;
  828. $model->isNewRecord = true;
  829. $model->save();
  830. $model=new Lead();
  831. $model->scenario = 'Lead';
  832. $updatedOn = time();
  833. Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  834. }
  835. $red = @$_REQUEST['red'];
  836. if($this->action->id=='AllocateLeads' && $red == 1) {
  837. $this->redirect(array('leads/lead_list'));
  838. } else {
  839. $this->redirect(array('leads/fresh_leads'));
  840. }
  841. //$this->redirect(array('leads/lead_list'));
  842. }
  843. public function actionAllocateLeadswithcount()
  844. {
  845. $Id = $_REQUEST['userids'];
  846. $teamId = @$_REQUEST['Team']['teamId'];
  847. $userId = $_REQUEST['Team']['teamMemberId'];
  848. $updatedBy = @$_SESSION['id'];
  849. foreach($Id as $key=>$value){
  850. $model = new AllocatedLeads();
  851. $model->scenario = 'AllocatedLeads';
  852. $model->setAttributes(array(
  853. 'currentAllocatedDate' => time(), //additional data you want to insert
  854. //'createdOn' => time(), //additional data you want to insert
  855. 'updatedOn' => time(), //additional
  856. 'updatedBy' => @$updatedBy, //additional
  857. 'createdBy' => @$updatedBy, //additional
  858. 'leadStatusId' => '35', //additional //additional
  859. ));
  860. $leadId = @$value;
  861. $model->leadId = @$value;
  862. $model->userId = @$userId;
  863. $model->teamId = @$teamId;
  864. //echo @$teamId.' - '.@$userId.' - '.@$leadId;
  865. $model->allocatedId = null;
  866. $model->isNewRecord = true;
  867. $model->save();
  868. $model=new Lead();
  869. $model->scenario = 'Lead';
  870. $updatedOn = time();
  871. //Lead::model()->updateByPk(@$value, array('currentAllocatedId'=>@$userId,'leadStatusId'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  872. }
  873. $red = @$_REQUEST['red'];
  874. $chkleadAllocatedOrNot = Lead::model()->findByPk($leadId);
  875. $oldallocatedid = $chkleadAllocatedOrNot['currentAllocatedId'];
  876. if(isset($oldallocatedid) && !empty($oldallocatedid)){
  877. $checkLeadExistorNot=Leadallcount::model()->findByAttributes(array('userid'=>$oldallocatedid,'key'=>'2014'));
  878. if(count($checkLeadExistorNot) > 0){
  879. Leadallcount::model()->updateByPk(@$checkLeadExistorNot['id'], array('userid'=>@$oldallocatedid,'key'=>'2014','value'=>'35','updatedBy'=>@$updatedBy,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  880. } else {
  881. $leadcount = new Leadallcount();
  882. $leadcount->setAttributes(array(
  883. 'userid' => $oldallocatedid, //additional data you want to insert
  884. 'key' => 2014, //additional data you want to insert
  885. 'value' => 1, //additional data you want to insert
  886. 'createdOn' => time(), //additional data you want to insert
  887. 'updatedOn' => time(), //additional
  888. 'updatedBy' => time(), //additional
  889. 'createdBy' => time(), //additional //additional
  890. ));
  891. $leadcount->save(false);
  892. }
  893. }
  894. /*$leadcount->setAttributes(array(
  895. 'userid' => time(), //additional data you want to insert
  896. 'key' => 2014, //additional data you want to insert
  897. 'value' => 1, //additional data you want to insert
  898. 'createdOn' => time(), //additional data you want to insert
  899. 'updatedOn' => time(), //additional
  900. 'updatedBy' => time(), //additional
  901. 'createdBy' => time(), //additional //additional
  902. ));
  903. $leadcount->save(false);*/
  904. die;
  905. if($this->action->id=='AllocateLeads' && $red == 1) {
  906. $this->redirect(array('leads/lead_list'));
  907. } else {
  908. $this->redirect(array('leads/fresh_leads'));
  909. }
  910. //$this->redirect(array('leads/lead_list'));
  911. }
  912. /**
  913. * This is the 'lead_list_allocator' action that is invoked
  914. * when an action is not explicitly requested by users.
  915. */
  916. public function actionlead_assign()
  917. {
  918. $model = new Lead();
  919. $model->scenario = 'Lead';
  920. $leadId = $_REQUEST['AssignLead']['leadId'];
  921. $userId = $_REQUEST['AssignLead']['userId'];
  922. $assign = $_REQUEST['AssignLead']['assign'];
  923. if($leadId!='') {
  924. $updatedOn = time();
  925. $chkleadStatus = Lead::model()->findByPk($leadId);
  926. $existsOrNot = $chkleadStatus['leadStatusId'];
  927. $leadStatusIdUpdate = $existsOrNot?$existsOrNot:'34';
  928. if($leadStatusIdUpdate == 34){
  929. $leadStatusIdUpdate = 35;
  930. } else {
  931. $leadStatusIdUpdate = $leadStatusIdUpdate;
  932. }
  933. if($assign=='open') {
  934. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>'','status'=>'Active','leadStatusId'=>34,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>''));
  935. } elseif($assign=='self'){
  936. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$userId,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  937. } else {
  938. Lead::model()->updateByPk(@$leadId, array('currentAllocatedId'=>@$assign,'status'=>'Allocated','leadStatusId'=>@$leadStatusIdUpdate,'updatedBy'=>@$userId,'updatedOn'=>@$updatedOn,'currentAllocatedDate'=>@$updatedOn));
  939. }
  940. echo CJSON::encode(array(
  941. 'status'=>'success'
  942. ));
  943. Yii::app()->end();
  944. //$this->redirect(array('leads/leads_details', 'leadId'=>@$leadId));
  945. } else {
  946. $this->redirect(array('leads/lead_list'));
  947. }
  948. }
  949. /**
  950. * This is the 'roles' action that is invoked
  951. * when an action is not explicitly requested by users.
  952. */
  953. public function actionarchive_leads()
  954. {
  955. // renders the view file 'protected/views/site/index.php'
  956. // using the default layout 'protected/views/layouts/main.php'
  957. $model=new Lead();
  958. //$model=Lead::model()->findAll();
  959. $this->render('archive_leads',array('model'=>$model));
  960. }
  961. /**
  962. * This is the 'roles' action that is invoked
  963. * when an action is not explicitly requested by users.
  964. */
  965. public function actionbulk_import_leads()
  966. {
  967. // renders the view file 'protected/views/site/index.php'
  968. // using the default layout 'protected/views/layouts/main.php'
  969. $model=new Lead();
  970. $this->render('bulk_import_lead',array('model'=>$model));
  971. }
  972. /**
  973. * This is the 'roles' action that is invoked
  974. * when an action is not explicitly requested by users.
  975. */
  976. public function actionjunk_leads()
  977. {
  978. // renders the view file 'protected/views/site/index.php'
  979. // using the default layout 'protected/views/layouts/main.php'
  980. $this->render('junk_leads');
  981. }
  982. /**
  983. * This is the 'module master' action that is invoked
  984. * when an action is not explicitly requested by users.
  985. */
  986. public function actionmodule_master()
  987. {
  988. // renders the view file 'protected/views/site/index.php'
  989. // using the default layout 'protected/views/layouts/main.php'
  990. $model=new ModuleMaster();
  991. $model->scenario = 'ModuleMaster';
  992. if(!empty($_GET['moduleId']))
  993. {
  994. $moduleId=$_GET['moduleId'];
  995. $model=ModuleMaster::model()->findByPk($moduleId);
  996. }
  997. if(!empty($_POST['ModuleMaster']['moduleId']))
  998. {
  999. $moduleId=$_POST['ModuleMaster']['moduleId'];
  1000. $model=ModuleMaster::model()->findByPk($moduleId);
  1001. }
  1002. if(isset($_POST['ModuleMaster']))
  1003. {
  1004. $model->setAttributes(array(
  1005. 'createdOn' => time(), //additional data you want to insert
  1006. 'updatedOn' => time(), //additional
  1007. 'updatedBy' => time(), //additional
  1008. 'createdBy' => time(),
  1009. 'status' => 'Activated', //additional //additional
  1010. ));
  1011. foreach($_POST['ModuleMaster'] as $name=>$value)
  1012. {
  1013. $model->$name=$value;
  1014. }
  1015. if($model->validate()){
  1016. $model->save();
  1017. $model2=ModuleMaster::model()->findAll();
  1018. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  1019. Yii::app()->user->setFlash('module_master_msg_success','Successfully Inserted');
  1020. } else {
  1021. Yii::app()->user->setFlash('module_master_msg_error','Please check. error occured');
  1022. $this->render('module_master',array('model'=>$model));
  1023. }
  1024. } else {
  1025. $model2=ModuleMaster::model()->findAll();
  1026. //Yii::app()->user->setFlash('lead_stage_msg_error','Please check. error occured');
  1027. $this->render('module_master',array('model'=>$model,'model2'=>$model2));
  1028. }
  1029. }
  1030. /**
  1031. * This is the action to handle external exceptions.
  1032. */
  1033. public function actionError()
  1034. {
  1035. if($error=Yii::app()->errorHandler->error)
  1036. {
  1037. if(Yii::app()->request->isAjaxRequest)
  1038. echo $error['message'];
  1039. else
  1040. $this->render('error', $error);
  1041. }
  1042. }
  1043. /**
  1044. * Displays the contact page
  1045. */
  1046. public function actionContact()
  1047. {
  1048. $model=new ContactForm;
  1049. if(isset($_POST['ContactForm']))
  1050. {
  1051. $model->attributes=$_POST['ContactForm'];
  1052. if($model->validate())
  1053. {
  1054. $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  1055. $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  1056. $headers="From: $name <{$model->email}>\r\n".
  1057. "Reply-To: {$model->email}\r\n".
  1058. "MIME-Version: 1.0\r\n".
  1059. "Content-type: text/plain; charset=UTF-8";
  1060. mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  1061. Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  1062. $this->refresh();
  1063. }
  1064. }
  1065. $this->render('contact',array('model'=>$model));
  1066. }
  1067. /**
  1068. * Displays the login page
  1069. */
  1070. public function actionLogin()
  1071. {
  1072. $model=new User;
  1073. // if it is ajax validation request
  1074. if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  1075. {
  1076. echo CActiveForm::validate($model);
  1077. Yii::app()->end();
  1078. }
  1079. // collect user input data
  1080. if(isset($_POST['User']))
  1081. {
  1082. $model->attributes=$_POST['User'];
  1083. // validate user input and redirect to the previous page if valid
  1084. if($model->validate() && $model->login()){
  1085. $this->redirect(array('masters/dashboard'));
  1086. } else {
  1087. $this->redirect(Yii::app()->user->returnUrl);
  1088. }
  1089. }
  1090. // display the login form
  1091. $this->render('login',array('model'=>$model));
  1092. }
  1093. /**
  1094. * Logs out the current user and redirect to homepage.
  1095. */
  1096. public function actionLogout()
  1097. {
  1098. setcookie ('PHPSESSID', '', time(), '/', '', 0, 0); // Destroy the cookie.
  1099. Yii::app()->user->logout();
  1100. $this->redirect(Yii::app()->homeUrl);
  1101. }
  1102. public function getPageType()
  1103. {
  1104. return "Leads";
  1105. }
  1106. public function init(){
  1107. $obj =new RecentlyViewedController(); // preparing object
  1108. $data=$obj->actionUserRoleAccess();
  1109. $moduleArray=array();
  1110. if(Yii::app()->session->get('type')=='superadmin'){
  1111. $moduleArray['read']='yes';
  1112. $moduleArray['write']='yes';
  1113. $moduleArray['delete']='yes';
  1114. }else{
  1115. foreach($data as $key=>$value){
  1116. if($data[$key]->modules->moduleName=='Leads'){
  1117. $moduleArray['moduleName']=$data[$key]->modules->moduleName;
  1118. $moduleArray['read']=$data[$key]->read;
  1119. $moduleArray['write']=$data[$key]->write;
  1120. $moduleArray['delete']=$data[$key]->delete;
  1121. }
  1122. }
  1123. }
  1124. return $moduleArray;
  1125. }
  1126. public function getNameFromNumber($num) {
  1127. $numeric = $num % 26;
  1128. $letter = chr(65 + $numeric);
  1129. $num2 = intval($num / 26);
  1130. if ($num2 > 0) {
  1131. return getNameFromNumber($num2 - 1) . $letter;
  1132. } else {
  1133. return $letter;
  1134. }
  1135. }
  1136. /*function actionexportArchiveList()
  1137. {
  1138. // generate a resultset
  1139. $model=new User;
  1140. $model=User::model()->findAll();
  1141. // render data to xlsx format and echo resultant file back to browser.
  1142. ExcelExporter::sendAsXLS($model, true, 'closedLeads.xls');
  1143. }*/
  1144. public function actionDownloadLeadTemp(){
  1145. Yii::import('ext.phpexcel.XPHPExcel');
  1146. $objPHPExcel= XPHPExcel::createPHPExcel();
  1147. $objPHPExcel->getProperties()->setCreator("LeadTemplate")
  1148. ->setLastModifiedBy("LeadTemplate")
  1149. ->setTitle("LeadTemplate")
  1150. ->setSubject("LeadTemplate")
  1151. ->setDescription("LeadTemplate.")
  1152. ->setKeywords("LeadTemplate")
  1153. ->setCategory("LeadTemplate");
  1154. //echo $total_excelColumns=$this->getNameFromNumber(4);
  1155. $total_excelColumns='I';
  1156. // Rename worksheet
  1157. $objPHPExcel->getActiveSheet()->setTitle('ClosedLeads');
  1158. $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
  1159. $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
  1160. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);
  1161. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
  1162. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
  1163. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1164. $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
  1165. $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(30);
  1166. $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);
  1167. $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
  1168. $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);
  1169. $objPHPExcel->getActiveSheet()->duplicateStyleArray(
  1170. array(
  1171. 'font' => array(
  1172. 'name' => 'Times New Roman',
  1173. 'bold' => true,
  1174. 'italic' => false,
  1175. 'size' => 12
  1176. ),
  1177. 'borders' => array(
  1178. 'top' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1179. 'bottom' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1180. 'left' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE),
  1181. 'right' => array('style' => PHPExcel_Style_Border::BORDER_DOUBLE)
  1182. ),
  1183. 'alignment' => array(
  1184. 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  1185. 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
  1186. 'wrap' => true
  1187. )
  1188. ),
  1189. 'A1:'.$total_excelColumns.'1'
  1190. );
  1191. // Set active sheet index to the first sheet, so Excel opens this as the first sheet
  1192. // Add some data
  1193. $objPHPExcel->setActiveSheetIndex(0)
  1194. ->setCellValue('A1', 'Name')
  1195. ->setCellValue('B1', 'City')
  1196. ->setCellValue('C1', 'Email')
  1197. ->setCellValue('D1', 'Mobile')
  1198. ->setCellValue('E1', 'Suminsured')
  1199. ->setCellValue('F1', 'Age')
  1200. ->setCellValue('G1', 'No. Of Members')
  1201. ->setCellValue('H1', 'Date on submit')
  1202. ->setCellValue('I1', 'Lead Source');
  1203. // Miscellaneous glyphs, UTF-8
  1204. $objPHPExcel->setActiveSheetIndex(0)
  1205. ->setCellValue('A2', 'Lead Name')
  1206. ->setCellValue('B2', 'city')
  1207. ->setCellValue('C2', 'test@yesk.com')
  1208. ->setCellValue('D2', '9999999999')
  1209. ->setCellValue('E2', '56')
  1210. ->setCellValue('F2', '23')
  1211. ->setCellValue('G2', 'test')
  1212. ->setCellValue('H2', '07-Sep-2013')
  1213. ->setCellValue('I2', 'test');
  1214. //To create new sheet in current file
  1215. /*$objPHPExcel->createSheet(1);
  1216. $objPHPExcel->setActiveSheetIndex(1);
  1217. $objPHPExcel->getActiveSheet()->setTitle('Title');
  1218. */
  1219. // Redirect output to a client’s web browser (Excel5)
  1220. header('Content-Type: application/vnd.ms-excel');
  1221. header('Content-Disposition: attachment;filename="LeadTemplates.xls"');
  1222. header('Cache-Control: max-age=0');
  1223. // If you're serving to IE 9, then the following may be needed
  1224. header('Cache-Control: max-age=1');
  1225. // If you're serving to IE over SSL, then the following may be needed
  1226. header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
  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. public function actionImportLeadTemplate(){
  1235. $model=new lead();
  1236. $data='';
  1237. $final_arr=@$_POST['final_arr']?@$_POST['final_arr']:'';
  1238. if(isset($_POST['ImportLeads']) && empty($final_arr) && !empty($_FILES['Lead']['name']['import'])){
  1239. Yii::import('ext.phpexcelreader.JPhpExcelReader');
  1240. $model->attributes='import';
  1241. $model->import=CUploadedFile::getInstance($model,'import');
  1242. $prefix=substr(time(),0,5);
  1243. $folder = '/tempdata';
  1244. $model->import->saveAs($folder.$prefix.$model->import);
  1245. $data=new JPhpExcelReader($folder.$prefix.$model->import);
  1246. //$this->render('bulk_import_lead',array('data'=>$data,'model'=>$model));
  1247. //$this->redirect(Yii::app()->createUrl('leads/bulk_import_leads'),array('data'=>$data,'model'=>$mod…

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