PageRenderTime 176ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 1ms

/app/controllers/creativezones_controller_bakup.php

https://bitbucket.org/fxrialab/spsp_editor
PHP | 3851 lines | 2536 code | 783 blank | 532 comment | 396 complexity | 4a890db0242573c7d2df323b93eae2e4 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0
  1. <?
  2. class CreativezonesController extends AppController {
  3. var $name='Creativezones';
  4. var $helpers = array('Html','javascript','error','Ajax','Friendsurl','Common');
  5. var $uses=array('Creativezone','User','Creative_favorites','Creative_favorite_tags','Creative_tickets','Transaction_creatives');
  6. var $components = array('Newdir','Thumbnail','Thumbnailc','Zipfile','Download','Cartmail','Creative','Sendmail');
  7. //ok
  8. function index() {
  9. //$this->checkSession();
  10. $this->pageTitle = 'ScrapFOTO&trade; Home';
  11. //$this->layout = 'creativehome';
  12. $this->layout = 'creativedetail';
  13. $this->homepageslideInfo('ScrapFOTO');
  14. //Initializing all the bradcamp back again so that it all starts all over again
  15. unset($_SESSION['bradcamp_creative']);
  16. $this->set("filename","index"); //filename should contain the name of the file that should be selected
  17. //_________________________________________________________________________________________________
  18. unset($_SESSION['buyTemplate']);
  19. //check creative_carts
  20. if(isset($_SESSION['UserId'])) {
  21. $sql = "SELECT Cart.id FROM creative_carts as Cart
  22. LEFT JOIN creative_cart_details CartDetail ON Cart.id = CartDetail.creative_cart_id
  23. LEFT JOIN creative_favorites Favorite ON Favorite.id = CartDetail.creative_favorite_id
  24. WHERE Cart.user_id ='".$_SESSION['UserId']."' AND Cart.pay_status='0' AND Favorite.is_republished ='0' AND Favorite.is_temp='1' ";
  25. $result = mysql_query($sql) or die(mysql_error());
  26. if(mysql_num_rows($result)>0) {
  27. //delete cart
  28. while($row=mysql_fetch_array($result)) {
  29. mysql_query("DELETE FROM creative_carts WHERE id='".$row['id']."' ") or die(mysql_error());
  30. }
  31. }
  32. //check delete favorite
  33. //mysql_query("DELETE FROM creative_favorites WHERE user_id='".$_SESSION['UserId']."' AND is_republished ='0' AND is_temp='1' ") or die(mysql_error());
  34. }
  35. $this->creativeType();
  36. $this->countFavCart();
  37. $this->getRankScrap();
  38. $this->getFeaturedScrap();
  39. $this->getPublicScrap();
  40. $this->render('index');
  41. }
  42. //ok ajax call get scrap in tab "Featured","Hight Rated","Recent"
  43. function featuredscrap($catlisttype=null) {
  44. $this->layout = 'profile_blank';
  45. ///////////////////////////////////////////////////// SQL FOR FEATURED SCRAP
  46. /* Pagination and PHOTO listing */
  47. $select = " Select X.is_featured,X.fileThumb2 as template_img,X.price,X.viewed,X.ssn_id,X.price,X.width,X.height,X.id,X.creation,X.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat";
  48. $from=" FROM creative_favorites X
  49. LEFT JOIN creative_favorites_details XCreativetypeDetail ON X.id = XCreativetypeDetail.creative_favorite_id
  50. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  51. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  52. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  53. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  54. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  55. $where=" WHERE X.is_blocked='0' AND X.is_temp='0' AND X.type='0' AND X.is_approved='1' AND X.is_stop_sell='0' ";
  56. if($catlisttype=='featured') {
  57. $where.=" AND X.is_featured='1' ";
  58. $morelink=$this->webroot.'creativezones/scrapxonglisting?listtype=featured';
  59. }
  60. $others=" group by X.id ";
  61. if($catlisttype=='mostvoted') {
  62. $others .=" order by photorat desc ";
  63. $morelink=$this->webroot.'creativezones/scrapxonglisting?listtype=mostvoted';
  64. }
  65. if(!$catlisttype) {
  66. $others.=" order by X.id desc";
  67. $morelink=$this->webroot.'creativezones/scrapxonglisting?listtype=recent';
  68. }
  69. $tabsql = $select.$from.$where. $others . ' LIMIT 12';
  70. $tabsql_res = mysql_query($tabsql);
  71. $this->set('query',$tabsql_res) ;
  72. $this->set('tabsql',$tabsql) ;
  73. $this->set('morelink',$morelink);
  74. /////////////////////////////////////////////////////////////////
  75. }
  76. //ok scrap listing
  77. function scrapxonglisting() {
  78. $this->layout = 'creativeinner';
  79. $catlisttype = '';
  80. if(isset($_REQUEST['listtype']) && $_REQUEST['listtype']!='')
  81. $catlisttype = $_REQUEST['listtype'];
  82. //this section is used to check whether to show the list based on the category given in the header section
  83. $scrapType=0;
  84. if(isset($this->params['url']['cat'])) {
  85. $scrapType=base64_decode($this->params['url']['cat']);
  86. $this->set("selTab",$scrapType);
  87. }
  88. ############################### Page Title & Head ############################
  89. $pageheadArr = array();
  90. $pageheadArr['featured'] = 'Featured';
  91. $pageheadArr['recent'] = 'Recent';
  92. $pageheadArr['mostvoted'] = 'Most Voted';
  93. $pageheadArr['mostcomment'] = 'Most Discussed';
  94. $pageheadArr['random'] = 'Random';
  95. $pageheadArr['favorite'] = 'Most Favorited ';
  96. $pageheadArr['tag'] = 'Tagged ';
  97. $pageheadArr['search'] = 'Search Result';
  98. $pageheadArr['mostviewed'] = 'Most Viewed';
  99. $pageheadArr['albumview'] = 'Album';
  100. $pageheadArr['seller'] = 'Seller';
  101. $pageheadArr['popular'] = 'Popular';
  102. if (array_key_exists($catlisttype, $pageheadArr)) {
  103. if($catlisttype=='albumview') {
  104. /* Album Name*/
  105. $albumNameSql = "Select IFNULL(creative_name,'') as albumName from creative_type where id='".base64_decode($_REQUEST['albumid'])."'";
  106. $albumNameSql_res = mysql_fetch_array(mysql_query($albumNameSql));
  107. $albumName = stripslashes($albumNameSql_res['albumName']) ;
  108. /**/
  109. $this->pageTitle = $pageheadArr[$catlisttype]. $albumName.' ScrapFOTO&trade;';
  110. $this->set('pagehead',$pageheadArr[$catlisttype].' : '. $albumName. ' ScrapFOTO&trade;');
  111. }
  112. else {
  113. if($catlisttype=='tag') {
  114. $this->pageTitle = $pageheadArr[$catlisttype].' ScrapFOTO&trade; : '. $_REQUEST['sortby'];
  115. $this->set('pagehead',$pageheadArr[$catlisttype].' ScrapFOTO&trade; : '.$_REQUEST['sortby']);
  116. }
  117. else {
  118. if($catlisttype=='seller') {
  119. /* SELLER INFO */
  120. $sellinfo = " SELECT username from users where id='".base64_decode($_REQUEST['resaleby'])."'";
  121. $sellinfo_res = mysql_query($sellinfo);
  122. $sellinfo_arr = mysql_fetch_array($sellinfo_res);
  123. $this->pageTitle = 'ScrapFOTO&trade; '.$pageheadArr[$catlisttype] .' : '.$sellinfo_arr['username'];
  124. $this->set('pagehead','ScrapFOTO&trade; '.$pageheadArr[$catlisttype].' : '.$sellinfo_arr['username']);
  125. }
  126. else {
  127. $this->pageTitle = $pageheadArr[$catlisttype].' ScrapFOTO&trade;';
  128. $this->set('pagehead',$pageheadArr[$catlisttype].' ScrapFOTO&trade;');
  129. }
  130. }
  131. }
  132. }
  133. else {
  134. if($catlisttype=='category') {
  135. $scrapDetail=$this->getCreativeType($scrapType);
  136. $this->pageTitle = $scrapDetail['creative_name'];
  137. $this->set('pagehead',$scrapDetail['creative_name']);
  138. }
  139. else {
  140. $this->pageTitle = 'ScrapFOTO&trade;';
  141. $this->set('pagehead','ScrapFOTO&trade;');
  142. }
  143. }
  144. ############################### Page Title & Head ############################
  145. /* Pagination and PHOTO listing */
  146. $select = " Select X.is_featured,X.fileThumb2 as template_img,X.price,X.viewed,X.ssn_id,X.width,X.height,X.id,X.creation,X.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat";
  147. $from=" FROM creative_favorites X
  148. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  149. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  150. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  151. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  152. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  153. $where=" WHERE X.is_blocked='0' AND X.is_temp='0' AND X.type='0' AND X.is_approved='1' AND X.is_stop_sell='0'";
  154. if($catlisttype=='featured')
  155. $where.=" AND X.is_featured='1' ";
  156. if( $catlisttype=='albumview' && isset($_REQUEST['albumid']) && base64_decode($_REQUEST['albumid'])>0)
  157. $where.=" AND XCreativetype.id='".base64_decode($_REQUEST['albumid'])."' ";
  158. if($catlisttype=='tag')
  159. $where.=" AND X.id IN (Select creative_favorite_id from creative_favorite_tags where tagname Like '%".$_REQUEST['sortby']."%')";
  160. if($catlisttype=='search')
  161. $where.=" AND X.title LIKE '%".$_REQUEST['srchtxt']."%' OR X.id IN (Select creative_favorite_id from creative_favorite_tags where tagname Like '%".$_REQUEST['srchtxt']."%') ";
  162. if($catlisttype=='seller')
  163. $where.=" AND X.user_id='".base64_decode($_REQUEST['resaleby'])."' ";
  164. if($catlisttype=='category')
  165. $where.=" AND XCreativetype.id='".$scrapType."' ";
  166. $others=" group by X.id ";
  167. if($catlisttype=='mostvoted')
  168. $others .=" order by photorat desc ";
  169. if($catlisttype=='mostcomment')
  170. $others .=" order by photoreview desc ";
  171. if($catlisttype=='mostviewed')
  172. $others .=" order by X.viewed desc ";
  173. if($catlisttype=='random')
  174. $others .=" order by X.id desc , rand()";
  175. if($catlisttype=='favorite')
  176. $others .=" order by photofavored desc ";
  177. if($catlisttype=='')
  178. $others.=" order by X.id desc";
  179. if(isset($_REQUEST['sortby']) && $_REQUEST['sortby']!='')
  180. $PassParameter="listtype=".$catlisttype."&sortby=".$_REQUEST['sortby'];
  181. else {
  182. if(isset($catlisttype) && $catlisttype=='albumview')
  183. $PassParameter="listtype=".$catlisttype."&albumid=".$_REQUEST['albumid'];
  184. else {
  185. if(isset($_REQUEST['srchtxt']) && $_REQUEST['srchtxt']!='')
  186. $PassParameter="listtype=".$catlisttype."&srchtxt=".$_REQUEST['srchtxt'];
  187. else {
  188. if(isset($_REQUEST['resaleby']) && base64_decode($_REQUEST['resaleby'])>0)
  189. $PassParameter="listtype=".$catlisttype."&resaleby=".$_REQUEST['resaleby'];
  190. else {
  191. if($catlisttype=='category')
  192. $PassParameter="listtype=".$catlisttype.'&cat='.base64_encode($scrapType) ;
  193. else
  194. $PassParameter="listtype=".$catlisttype;
  195. }
  196. }
  197. }
  198. }
  199. $fltr='';
  200. $CountField="X.id";
  201. $this->set("controller","creativezones");
  202. $this->set("action","scrapxonglisting");
  203. $this->set("parameter",$PassParameter);
  204. $this->set("fltr",$fltr);
  205. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  206. if(isset($this->params['url']['Page']) || (isset($fltr) && $fltr!="") ) {
  207. $this->set('pagehead','Most Recent');
  208. $this->render("scrapxonglisting2","ajax");
  209. }
  210. /**/
  211. $this->creativeType();
  212. $this->countFavCart();
  213. $this->getPublicScrap();
  214. }
  215. //ok scrap detail
  216. function scrapxong() {
  217. //$this->verifyserverUrl($_SERVER['REQUEST_URI']);
  218. $this->pageTitle = 'ScrapFOTO&trade;';
  219. $this->layout = 'creativedetail';
  220. ############################################ SCRAP XONG DETAILS
  221. $this->creativeType();
  222. $this->countFavCart();
  223. $this->getPublicScrap();
  224. $this->set('photoid',$_REQUEST['sxid']);
  225. //update viewed
  226. $select = "UPDATE creative_favorites SET viewed=viewed+1 WHERE id='".base64_decode($_REQUEST['sxid'])."' ";
  227. mysql_query($select);
  228. $select = " Select X.fileThumb2 as template_img,X.price,X.viewed,X.ssn_id,X.width,X.height,X.id,X.user_id,X.title,X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat";
  229. $from=" FROM creative_favorites X
  230. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  231. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  232. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  233. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  234. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  235. $where=" WHERE X.is_blocked='0' AND X.is_temp='0' AND X.id='".base64_decode($_REQUEST['sxid'])."' AND X.type='0' AND X.is_stop_sell='0' group by X.id";
  236. $photo_sql = $select . $from .$where;
  237. $photo_res = mysql_query($photo_sql);
  238. $photores_arr = mysql_fetch_array($photo_res);
  239. $photoUrl = FULL_BASE_URL.$this->webroot."creativezones/scrapxong?sxid=".$_REQUEST['sxid'];//DOMAIN
  240. $this->set('photoUrl',$photoUrl);
  241. $this->set('photoArr', $photores_arr);
  242. $this->set('photoTitle', $photores_arr['title']);
  243. $this->set('photoDesc', $photores_arr['description']);
  244. $this->set('photoImage', $photores_arr['template_img']);
  245. $this->set('photoImageId', $photores_arr['id']);
  246. $this->set('photoUsername', $photores_arr['username']);
  247. $this->set('photototalRating', $photores_arr['photorat']);
  248. $this->set('photototalReview', $photores_arr['photoreview']);
  249. $this->set('photoPrice', number_format($photores_arr['price'],2,'.',','));
  250. $checklover = "Select * from creative_favorite_lovers where creative_favorite_id='".base64_decode($_REQUEST['sxid'])."'" ;
  251. $checklover_res = mysql_query($checklover);
  252. $checklover_res_num = mysql_num_rows($checklover_res);
  253. $this->set('nooflover', $checklover_res_num);
  254. ##### Check for the review already posted or not
  255. $numberpreview=0;
  256. if(isset($_SESSION['UserId'])) {
  257. $checkbackdropreview = "SELECT * FROM creative_favorite_comments where creative_favorite_id='".base64_decode($_REQUEST['sxid'])."' and user_id='".$_SESSION['UserId']."'";
  258. $checkbackdropreview_res = mysql_query($checkbackdropreview);
  259. $numberpreview = mysql_num_rows($checkbackdropreview_res);
  260. }
  261. $this->set('reviewposted', $numberpreview);
  262. #####
  263. ################################################### FOR NEXT AND PREVIOUS #######################
  264. $Imgselect="
  265. SELECT CF.id,title,template_img
  266. FROM creative_favorites CF,creative_favorites_details CFDTL
  267. WHERE CF.id=CFDTL.creative_favorite_id AND CF.type='0'
  268. GROUP BY CF.id ORDER BY CF.id DESC
  269. " ;
  270. $Imgselect_res = mysql_query($Imgselect);
  271. $Imgarray = array();
  272. while($Imgselect_arr = mysql_fetch_array($Imgselect_res)) {
  273. //$Imgarray['image'.$Imgselect_arr['id']] = $Imgselect_arr['id'] ;
  274. $Imgarray[] = $Imgselect_arr['id'] ;
  275. }
  276. //pr($Imgarray);
  277. //echo base64_decode($_REQUEST['pid']) ;
  278. $searchKey = array_search(base64_decode($_REQUEST['sxid']),$Imgarray) ;
  279. // Next
  280. $searchKeyNext = ($searchKey + 1);
  281. $searchKeyPrev = ($searchKey - 1);
  282. if (array_key_exists($searchKeyNext, $Imgarray)) {
  283. $this->set('nxtImage',$Imgarray[$searchKeyNext]);
  284. }
  285. // Prev
  286. if (array_key_exists($searchKeyPrev, $Imgarray)) {
  287. $this->set('prevImage',$Imgarray[$searchKeyPrev]);
  288. }
  289. ################################################### FOR NEXT AND PREVIOUS #######################
  290. ########
  291. }
  292. //checking
  293. function creativetemplate() {
  294. //$this->checkSession();
  295. $this->pageTitle = 'ScrapFOTO&trade; - Create Template';
  296. $this->layout = 'creativehome';
  297. $this->creativeType();
  298. //This ct variable comes from INDEX page and CREATIVETEMPLATE page
  299. //This variable contains the category Id
  300. if(isset($this->params['url']['ct']))
  301. $id=base64_decode($this->params['url']['ct']);
  302. //This ct variable comes from CREATIVETEMPLATE page
  303. $tmpImg=0;
  304. if(isset($this->params['url']['pg']))
  305. $tmpImg=base64_decode($this->params['url']['pg']);
  306. $themeId=0;
  307. if(isset($this->params['url']['tmplate']))
  308. $themeId=base64_decode($this->params['url']['tmplate']);
  309. //this variable is used to show the selected section in the accordian tag
  310. $this->set("cType",$id);
  311. $this->set("cTemplate",$tmpImg);
  312. $this->set("themeId",$themeId);
  313. //Initializing all the bradcamp back again so that it all starts all over again
  314. $this->set("filename","creativetemplate"); //filename should contain the name of the file that should be selected
  315. $_SESSION['bradcamp_creative'][20]=$this->params['action']; //we are passing the name of the file to keep track which step is visited
  316. $this->set("nextpage","creativezone");
  317. //_________________________________________________________________________________________________
  318. $this->countFavCart();
  319. /*
  320. // getting out the template name under the type
  321. if(isset($id)) {
  322. $templateName = array();
  323. $tempname="
  324. SELECT CP.*
  325. FROM creative_type CT,creative_template_pages CP
  326. WHERE CT.id=CP.creative_type_id AND CT.id='".$id."' AND block='0'
  327. ORDER BY CP.template_type ASC,CP.title ASC
  328. ";
  329. $tempname_res = mysql_query($tempname) or die('Line number '.__LINE__. mysql_error());
  330. $tempNum = mysql_num_rows($tempname_res);
  331. if($tempNum > 0) {
  332. $i=0;
  333. while($rwTmp = mysql_fetch_assoc($tempname_res)) {
  334. if($i==0) {
  335. $defaultTmpId=$rwTmp['id'];
  336. $this->set("defaultTemplateId",$defaultTmpId);
  337. }
  338. $i++;
  339. $templateName[$rwTmp['id']]=array($rwTmp['title'],$rwTmp['template_img'],$rwTmp['price'],$rwTmp['template_type']);
  340. }
  341. }
  342. }
  343. $this->set('templateImg',$templateName);
  344. //Getting the large thimbnail image
  345. if(isset($tmpImg) && $tmpImg!=0) {
  346. $this->templateDetail($tmpImg);
  347. $this->render("template","ajax");
  348. }
  349. if(isset($this->params['url']['tpage'])) {
  350. //print "test";
  351. $tPage=base64_decode($this->params['url']['tpage']);
  352. $this->templateDetail($tPage);
  353. //exit;
  354. $this->render("template","ajax");
  355. }
  356. */
  357. }
  358. //checking
  359. function creativetemplatezone() {
  360. $this->checkSession();
  361. $this->pageTitle = 'ScrapFOTO&trade; - Creative Zone';
  362. $this->layout = 'creativehome';
  363. $this->creativeType();
  364. //Initializing all the bradcamp back again so that it all starts all over again
  365. $this->set("filename","creativetemplatezone"); //filename should contain the name of the file that should be selected
  366. $this->set("nextpage","creative_favorite");
  367. //_________________________________________________________________________________________________
  368. if(isset($this->params['url']['tmp'])) {
  369. $tmpImg=base64_decode($this->params['url']['tmp']);
  370. $tmpImg = $this->templateDetail($tmpImg);
  371. if($tmpImg==0) {
  372. $this->redirect('/creativezones/index');
  373. }else {
  374. //emty cart current
  375. $sql ="SELECT id FROM creative_carts WHERE pay_status='0' ";
  376. $result = mysql_query($sql) or die(mysql_error());
  377. if(mysql_num_rows($result)>0) {
  378. while($row=mysql_fetch_array($result)) {
  379. $sql ="DELETE FROM creative_cart_details WHERE creative_cart_id='".$row['id']."' ";
  380. mysql_query($sql) or die(mysql_error());
  381. }
  382. }
  383. //add favorite
  384. if(!isset($_SESSION['buyTemplate']['tmpId'])) {
  385. $_SESSION['buyTemplate']['tmpId'] = $tmpImg;
  386. //add to favorite
  387. $fav = $this->Creative_favorites->findById($tmpImg);
  388. $fav['Creative_favorites']['id'] = null;
  389. $fav['Creative_favorites']['user_id'] = $_SESSION['UserId'];
  390. $fav['Creative_favorites']['is_temp'] = 1;
  391. $fav['Creative_favorites']['type'] = 1;
  392. $fav['Creative_favorites']['is_featured'] = 0;
  393. $fav['Creative_favorites']['is_republished'] = 0;
  394. $this->Creative_favorites->create();
  395. $this->Creative_favorites->save($fav);
  396. $idNew = $this->Creative_favorites->id;
  397. $_SESSION['buyTemplate']['idNew'] = $idNew;
  398. }
  399. }
  400. }
  401. $this->countFavCart();
  402. //case create form header
  403. if(isset($_POST['widthScrap'])) {
  404. $this->set('widthScrap',$_POST['widthScrap']);
  405. $this->set('heightScrap',$_POST['heightScrap']);
  406. $this->set('titleScrap',$_POST['titleScrap']);
  407. }
  408. }
  409. //checking
  410. function creative_favorite() {
  411. $this->checkSession();
  412. $this->pageTitle = 'ScrapFOTO&trade; - My Favorite';
  413. $this->layout = 'creativehome';
  414. $this->creativeType();
  415. //This ct variable comes from INDEX page and CREATIVETEMPLATE page
  416. $tmpImg=0;
  417. if(isset($this->params['url']['tmp'])) {
  418. $tmpImg=base64_decode($this->params['url']['tmp']);
  419. $tmpImg = $this->templateDetail($tmpImg);
  420. }else if(isset($_SESSION['buyTemplate']['tmpId'])) {
  421. $tmpImg = $_SESSION['buyTemplate']['tmpId'];
  422. $tmpImg = $this->templateDetail($tmpImg);
  423. }
  424. if(isset($_POST['ssn_id'])) {
  425. $ssn_id = $_POST['ssn_id'];
  426. $fav = $this->Creative_favorites->findBySsn_id(base64_decode($_POST['ssn_id']));
  427. if(!$fav) {//create
  428. $this->Creative_favorites->create();
  429. }
  430. else {//update
  431. $this->Creative_favorites->id = $fav['Creative_favorites']['id'];
  432. }
  433. $fav['Creative_favorites']['ssn_id'] = base64_decode($_POST['ssn_id']);
  434. $fav['Creative_favorites']['user_id'] = $_SESSION['UserId'];
  435. $fav['Creative_favorites']['title'] = base64_decode($_POST['title']);
  436. $fav['Creative_favorites']['description'] = $_POST['description'];
  437. $fav['Creative_favorites']['price'] = $_POST['price'];
  438. $fav['Creative_favorites']['width'] = $_POST['width'];
  439. $fav['Creative_favorites']['height'] = $_POST['height'];
  440. $fav['Creative_favorites']['fileThumb'] = base64_decode($_POST['fileThumb']);
  441. $fav['Creative_favorites']['fileThumb2'] = base64_decode($_POST['fileThumb2']);
  442. $fav['Creative_favorites']['fileThumb3'] = base64_decode($_POST['fileThumb3']);
  443. $fav['Creative_favorites']['fileData'] = base64_decode($_POST['fileData']);
  444. $fav['Creative_favorites']['fileZip'] = base64_decode($_POST['fileZip']);
  445. $fav['Creative_favorites']['is_temp'] = 0;
  446. $fav['Creative_favorites']['creative_type_id'] = $_POST['creative_type_id'];
  447. $fav['Creative_favorites']['type'] = $_POST['type'];
  448. $fav['Creative_favorites']['is_featured'] = $_POST['is_featured'];
  449. $fav['Creative_favorites']['is_temp'] = $fav['Creative_favorites']['is_featured'];
  450. if($fav['Creative_favorites']['type']==0) {//public
  451. $featuredAmount=$this->getConfigAmount('creative artist price');
  452. $fav['Creative_favorites']['price'] = $featuredAmount['config_value'];
  453. }
  454. $resultSave = $this->Creative_favorites->save($fav);//return 1/null
  455. //insert tag
  456. if($resultSave && $_POST['tag']!='') {
  457. $tag['Creative_favorite_tags']['creative_favorite_id'] = $this->Creative_favorites->id;
  458. $tag['Creative_favorite_tags']['user_id'] = $_SESSION['UserId'];
  459. $tag['Creative_favorite_tags']['tagname'] = $_POST['tag'];
  460. $this->Creative_favorite_tags->create();
  461. $this->Creative_favorite_tags->save($tag);
  462. }
  463. if($fav['Creative_favorites']['type']==0) {
  464. if($resultSave && $fav['Creative_favorites']['is_featured']==1) {
  465. $this->redirect("creativezones/creative_featured?lid=".base64_encode($this->Creative_favorites->id));
  466. exit();
  467. }else {
  468. $this->redirect("creativezones/featuredsuccess?lid=".base64_encode($this->Creative_favorites->id));
  469. }
  470. }
  471. }
  472. if(isset($_POST['actionCall']) && $_POST['actionCall']=='exit') {
  473. $this->redirect('/creativezones/index');
  474. }
  475. if($tmpImg==0) {
  476. unset($_SESSION['buyTemplate']);
  477. $favs = null;
  478. $result = mysql_query("SELECT * FROM creative_favorites WHERE user_id='".$_SESSION['UserId']."' AND is_temp='0' AND is_republished='1' ") or die("Error on line :".__LINE__.mysql_error());
  479. if(mysql_num_rows($result)>0) {
  480. $favs = $result;
  481. }
  482. $this->set("favs",$favs);
  483. }else if(isset($_SESSION['buyTemplate']['idNew'])) {
  484. $favs = null;
  485. $result = mysql_query("SELECT * FROM creative_favorites WHERE user_id='".$_SESSION['UserId']."' AND id='".$_SESSION['buyTemplate']['idNew']."' ") or die("Error on line :".__LINE__.mysql_error());
  486. if(mysql_num_rows($result)>0) {
  487. $favs = $result;
  488. }
  489. $this->set("favs",$favs);
  490. }
  491. $this->countFavCart();
  492. //Initializing all the bradcamp back again so that it all starts all over again
  493. $this->set("filename","creative_favorite");
  494. $this->set("nextpage","mycart");
  495. //_________________________________________________________________________________________________
  496. $this->set("recenttype","creative_favorite");
  497. $this->getCartDetails();
  498. }
  499. //ok
  500. function creative_favorite_ajax() {
  501. if(isset($_POST['ssn_id'])) {
  502. $ssn_id = $_POST['ssn_id'];
  503. $fav = $this->Creative_favorites->findBySsn_id(base64_decode($_POST['ssn_id']));
  504. if(!$fav) {
  505. $fav['Creative_favorites']['ssn_id'] = base64_decode($_POST['ssn_id']);
  506. $fav['Creative_favorites']['user_id'] = $_SESSION['UserId'];
  507. $fav['Creative_favorites']['title'] = base64_decode($_POST['title']);
  508. $fav['Creative_favorites']['description'] = $_POST['description'];
  509. $fav['Creative_favorites']['price'] = $_POST['price'];
  510. $fav['Creative_favorites']['width'] = $_POST['width'];
  511. $fav['Creative_favorites']['height'] = $_POST['height'];
  512. $fav['Creative_favorites']['fileThumb'] = base64_decode($_POST['fileThumb']);
  513. $fav['Creative_favorites']['fileThumb2'] = base64_decode($_POST['fileThumb2']);
  514. $fav['Creative_favorites']['fileThumb3'] = base64_decode($_POST['fileThumb3']);
  515. $fav['Creative_favorites']['fileData'] = base64_decode($_POST['fileData']);
  516. $fav['Creative_favorites']['fileZip'] = base64_decode($_POST['fileZip']);
  517. $fav['Creative_favorites']['is_temp'] = 0;
  518. $fav['Creative_favorites']['creative_type_id'] = $_POST['creative_type_id'];
  519. $fav['Creative_favorites']['type'] = $_POST['type'];
  520. $fav['Creative_favorites']['is_featured'] = $_POST['is_featured'];
  521. $this->Creative_favorites->create();
  522. $resultSave = $this->Creative_favorites->save($fav);//return 1/null
  523. //insert tag
  524. if($resultSave && $_POST['tag']!='') {
  525. $tag['Creative_favorite_tags']['creative_favorite_id'] = $this->Creative_favorites->id;
  526. $tag['Creative_favorite_tags']['user_id'] = $_SESSION['UserId'];
  527. $tag['Creative_favorite_tags']['tagname'] = $_POST['tag'];
  528. $this->Creative_favorite_tags->create();
  529. $this->Creative_favorite_tags->save($tag);
  530. }
  531. }
  532. }
  533. $this->countFavCart();
  534. $this->render("creative_favorite_ajax","ajax");
  535. }
  536. function creativeType() {
  537. $q1=mysql_query("SELECT * FROM creative_type WHERE is_delete='0' ORDER BY sequence ASC");
  538. $i=0;
  539. while($rwCr=mysql_fetch_array($q1)) {
  540. if($i==0)
  541. $defaultCat[$rwCr['id']]=array($rwCr['creative_name'],$rwCr['creative_description'],$rwCr['creative_image']);
  542. $i++;
  543. $creativeType[$rwCr['id']]=array($rwCr['creative_name'],$rwCr['creative_description'],$rwCr['creative_image']);
  544. }
  545. $this->set("defaultType",$defaultCat);
  546. $this->set("creativeType",$creativeType);
  547. $type = 0;
  548. foreach($defaultCat as $key=>$value) {
  549. $type = $key;
  550. break;
  551. }
  552. if(isset($this->params['url']['cat'])) {
  553. $scrapType=base64_decode($this->params['url']['cat']);
  554. $detail = $this->getCreativeType($scrapType);
  555. if($detail) {
  556. $type = $detail['id'];
  557. }
  558. }
  559. $this->set('defaultCate',$type);
  560. }
  561. //checking
  562. function templateDetail($tmpImg) {
  563. $q1=mysql_query("SELECT * FROM creative_favorites WHERE id='".$tmpImg."' AND is_blocked='0' AND is_temp='0' AND is_approved='1' AND type='0' ") or die(mysql_error());
  564. if(mysql_num_rows($q1)>0) {
  565. $rwTmpImg=mysql_fetch_assoc($q1);
  566. $this->set("tmpid",base64_encode($rwTmpImg['ssn_id']));
  567. $this->set("tmp",base64_encode($tmpImg));
  568. return $tmpImg;
  569. }
  570. return 0;
  571. }
  572. //ok
  573. function getPublicScrap() {
  574. $select = " Select X.price,X.fileThumb2 as imagename,X.id,X.creation,X.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat";
  575. $from=" FROM creative_favorites X
  576. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  577. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  578. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  579. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  580. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  581. $where=" WHERE X.is_blocked='0' AND X.is_temp='0' AND X.type='0' AND X.is_approved='1' AND X.is_stop_sell='0'";
  582. $others=" group by X.id ";
  583. $others .=" order by photorat desc ";
  584. $queryCreative = $select . $from . $where .$others ;
  585. $queryCreativeFavorites=mysql_query($queryCreative) or die("Error on line :".__LINE__.mysql_error());
  586. $queryCreativeFavorites=mysql_query($queryCreative) or die("Error on line :".__LINE__.mysql_error());
  587. $this->set("publicScrap",$queryCreativeFavorites);
  588. $this->set("publicScrapSql",$queryCreative);
  589. }
  590. //ok
  591. function getRankScrap() {
  592. /*$select = " Select X.fileThumb2 as template_img,X.price,X.id,X.creation,X.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat";
  593. $from=" FROM creative_favorites X
  594. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  595. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  596. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  597. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  598. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  599. $where=" WHERE X.is_blocked='0' AND X.is_temp='0' AND X.type='0' AND X.is_approved='1' ";
  600. $others=" group by X.id ";
  601. $others .=" order by photorat desc LIMIT 21";
  602. $queryCreative = $select . $from . $where .$others ;
  603. $queryCreativeFavorites=mysql_query($queryCreative) or die("Error on line :".__LINE__.mysql_error());
  604. $this->set("publicRank",$queryCreativeFavorites);
  605. $this->set("publicRankSql",$queryCreative);
  606. */
  607. }
  608. //ok
  609. function getFeaturedScrap() {
  610. /*$select = " Select X.width, X.height, X.price, X.id,X.creation,X.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,XCreativetypeDetail.template_img,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat,Xalbum.price";
  611. $from=" FROM creative_favorites X
  612. LEFT JOIN creative_favorites_details XCreativetypeDetail ON X.id = XCreativetypeDetail.creative_favorite_id
  613. LEFT JOIN creative_template_pages Xalbum ON X.creative_template_page_id = Xalbum.id
  614. LEFT JOIN creative_type XCreativetype ON Xalbum.creative_type_id = XCreativetype.id
  615. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  616. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  617. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  618. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  619. $where=" WHERE X.is_blocked='0' AND X.is_temp='0' AND X.type='0' AND X.is_featured='1' AND X.is_approved='1' ";
  620. $others=" group by X.id ";
  621. $others .=" order by photorat desc LIMIT 21";
  622. $queryCreative = $select . $from . $where .$others ;
  623. $queryCreativeFavorites=mysql_query($queryCreative) or die("Error on line :".__LINE__.mysql_error());
  624. $this->set("publicFeatured",$queryCreativeFavorites);
  625. $this->set("publicFeaturedSql",$queryCreative);
  626. */
  627. }
  628. //ok
  629. function viewalltag() {
  630. $this->pageTitle = 'ScrapFOTO&trade; - View Tag';
  631. $this->layout = 'creativedetail';
  632. $this->creativeType();
  633. $this->getPublicScrap();
  634. }
  635. //ok
  636. function searchtag($alphasearch=null) {
  637. if($alphasearch)
  638. $searchtxt = "'".strtolower($alphasearch)."%'" ;
  639. else {
  640. if(isset($_REQUEST['txttagsearch']) && $_REQUEST['txttagsearch']!='')
  641. $searchtxt = "'%". strip_html_tags($_REQUEST['txttagsearch'])."%'";
  642. else
  643. $searchtxt='a%';
  644. }
  645. $tagarray = array();
  646. $tagsearchsql = "SELECT DISTINCT(tagname) FROM creative_favorite_tags where tagname!='' and tagname like ". $searchtxt ."";
  647. $tagsearchsql_res = mysql_query($tagsearchsql);
  648. while($tagsearchsql_arr = mysql_fetch_array($tagsearchsql_res)) {
  649. $tagarray[] = $tagsearchsql_arr['tagname'];
  650. }
  651. $this->set('tagsql',$tagsearchsql);
  652. $this->set('tagarray',$tagarray);
  653. $this->set('Numtagarray',mysql_num_rows($tagsearchsql_res));
  654. $this->set('searchtxt',$alphasearch);
  655. $this->render('searchtaglist', 'ajax');
  656. }
  657. //ok
  658. function scrapaddtocart($scrapxongid=null) {
  659. $queryCreativeFavorites=mysql_query("
  660. SELECT CF.title,CTP.price
  661. FROM creative_favorites CF,creative_template_pages CTP
  662. WHERE CF.id='".base64_decode($scrapxongid)."' AND CF.creative_template_page_id=CTP.id AND CF.type='0'");
  663. $fetchCreativeFavorites=mysql_fetch_assoc($queryCreativeFavorites);
  664. $productName=$fetchCreativeFavorites['title'];
  665. $price=$fetchCreativeFavorites['price'];
  666. if(isset($_SESSION['UserId'])) {
  667. $creativecartsql = "SELECT * from creative_carts WHERE user_id='".$_SESSION['UserId']."' and product_name='".$productName."' and ssn_id='".session_id()."' and pay_status='0'";
  668. $creativecartsql_res = mysql_query($creativecartsql);
  669. if(mysql_num_rows($creativecartsql_res)==0) {
  670. mysql_query("INSERT INTO
  671. creative_carts(user_id,product_name,price,qty,transaction_creative_id,pay_status,ssn_id)
  672. VALUES('".$_SESSION['UserId']."','".$productName."','".$price."','1','0','0','".session_id()."')") or die("Error on line : ".__LINE__.mysql_error());
  673. $lastId=mysql_insert_id();
  674. $queryCreativeFavoritesDetails=mysql_query("SELECT template_img FROM creative_favorites_details WHERE creative_favorite_id='".base64_decode($scrapxongid)."'");
  675. while($fetchCreativeFavoritesDetails=mysql_fetch_assoc($queryCreativeFavoritesDetails)) {
  676. mysql_query("INSERT INTO creative_cart_details(creative_cart_id,imagename) VALUES('".$lastId."','".$fetchCreativeFavoritesDetails['template_img']."')");
  677. }
  678. }
  679. }
  680. $this->countFavCart();
  681. $this->set('photoImageId',$scrapxongid);
  682. $this->render('cartitem', 'ajax');
  683. }
  684. function creative_login() {
  685. $uName=base64_decode($this->params['url']['u']);
  686. $password=$this->params['url']['p'];
  687. $id=0;
  688. if(isset($this->params['url']['ct']))
  689. $id=base64_decode($this->params['url']['ct']);
  690. //This ct variable comes from CREATIVETEMPLATE page
  691. $tmpImg=0;
  692. if(isset($this->params['url']['tmp']))
  693. $tmpImg=base64_decode($this->params['url']['tmp']);
  694. //This is the last iserted id in the favorite table
  695. $lastId=0;
  696. if(isset($this->params['url']['lid']))
  697. $lastId=base64_decode($this->params['url']['lid']);
  698. $someone=$this->userLogin($uName,$password);
  699. if(!empty($someone))
  700. $this->redirect("creativezones/creative_favorite?ct=".base64_encode($id)."&tmp=".base64_encode($tmpImg)."&lid=".base64_encode($lastId));
  701. }
  702. function featuredpayment() {
  703. /*
  704. $this->checkSession();
  705. $this->layout = 'previewpaymemnt';
  706. $this->render("paymentback");
  707. //This ct variable comes from INDEX page and CREATIVETEMPLATE page
  708. $id=0;
  709. if(isset($this->params['url']['ct']))
  710. $id=base64_decode($this->params['url']['ct']);
  711. //This ct variable comes from CREATIVETEMPLATE page
  712. $tmpImg=0;
  713. if(isset($this->params['url']['tmp']))
  714. $tmpImg=base64_decode($this->params['url']['tmp']);
  715. //This is the last iserted id in the favorite table
  716. //If lid means user comes to this page after saving the scrapbook
  717. //We are checking whether the user features the scrapblog or not if yes then ask for the payment
  718. $lastId=0;
  719. if(isset($this->params['url']['lid']))
  720. $lastId=base64_decode($this->params['url']['lid']);
  721. $this->set("cType",$id);
  722. $this->set("cTemplate",$tmpImg);
  723. $this->set("lastId",$lastId);
  724. if(!empty($this->data)) {
  725. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  726. $featuredAmount=$this->getConfigAmount('creative featured');
  727. $amountCharge=$this->data['creative']['amount'];
  728. if(isset($this->data['Event']['radiobutton'])) {
  729. if($this->data['Event']['radiobutton']=="paypal") {
  730. $this->itemName="ScrapFOTO&trade; fetaured";
  731. $this->amountPay=$amountCharge;
  732. $this->returnUrl=FULL_BASE_URL.$this->webroot."creativezones/creative_favorite";
  733. $this->notifyUrl=FULL_BASE_URL.$this->webroot."creativezones/featuredsuccess";
  734. $this->merchantEmail=$fetchAdminPaymentSetup['paypal_email'];
  735. $this->custom=$_SESSION['UserId']."^".$id."^".$tmpImg."^".$lastId;
  736. $this->paypal();
  737. }
  738. if($this->data['Event']['radiobutton']=="google") {
  739. $adminPayment=$fetchAdminPaymentSetup['gcheckout_email'];
  740. $adminPaymentDetails=explode("break",$adminPayment);
  741. $this->Gcheckout->gMerchantId=$adminPaymentDetails['0'];
  742. $this->Gcheckout->gMerchantKey=$adminPaymentDetails['1'];
  743. $this->Gcheckout->gItemName="ScrapFOTO&trade; Featured";
  744. $this->Gcheckout->gItemDesc="ScrapFOTO&trade; Featured";
  745. $this->Gcheckout->gQuantity=1;
  746. $this->Gcheckout->gPrice=$amountCharge;
  747. $this->Gcheckout->gReturnUrl=FULL_BASE_URL.$this->webroot."creativezones/creative_favorite";
  748. $this->Gcheckout->gNotifyUrl=FULL_BASE_URL.$this->webroot."creativezones/featuredsuccess";
  749. $this->Gcheckout->customData=$_SESSION['UserId']."^".$id."^".$tmpImg."^".$lastId."^".$amountCharge;
  750. $this->Gcheckout->google();
  751. }
  752. }
  753. }*/
  754. }
  755. function creative_featured() {
  756. $this->checkSession();
  757. $this->pageTitle = 'ScrapFOTO&trade; - Featured ScrapFOTO&trade;';
  758. $this->layout = 'creativehome';
  759. $this->creativeType();
  760. $this->getPublicScrap();
  761. $cartCount=$this->countFavCart();
  762. $tmpImg =0;
  763. $id =0;
  764. $lastId=0;
  765. if(isset($this->params['url']['lid']))
  766. $lastId=base64_decode($this->params['url']['lid']);
  767. $this->set("lastId",$lastId);
  768. $this->set("filename","creative_cart");
  769. $this->set("recenttype","creative_favorite");
  770. $featuredAmount=$this->getConfigAmount('creative featured');
  771. $this->set("featuredAmount",$featuredAmount);
  772. //getCartDetails;
  773. $sql = "SELECT *,CF.fileThumb2 as imagename FROM creative_favorites as CF WHERE CF.id='".$lastId."' LIMIT 1";
  774. $queryCreativeCarts=mysql_query($sql);
  775. $this->set("queryCreativeCarts",$queryCreativeCarts);
  776. $this->getUserDetails();
  777. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  778. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  779. }
  780. //checking
  781. function featured_payment_notify() {
  782. /*
  783. $this->Paypal->paypal_class();
  784. $this->Paypal->paypal_url = $this->paypalUrl; // testing paypal url
  785. //_______________________________________________IPN data received from PAYPAL and GOOGLE payment methods
  786. $paypal=0;
  787. if ($this->Paypal->validate_ipn()) {
  788. $paypal=1;
  789. if(isset($this->Paypal->ipn_data['payment_gross']) && ($this->Paypal->ipn_data['payment_gross'])!="") {
  790. $totalPay=$this->Paypal->ipn_data['payment_gross'];
  791. $custom=explode("^",$this->Paypal->ipn_data['custom']);
  792. $userId=$custom['0'];
  793. $lastId=$custom['1'];
  794. $invoice=$_POST['invoice'];
  795. $ticket=$custom['3'];
  796. }
  797. }
  798. //This section is used to catch from GOOGLE IPN data
  799. if(!$paypal) {
  800. //this section is used to update from google IPN data
  801. $xml_response = isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:file_get_contents("php://input");
  802. if($xml_response) {
  803. $gCustom=$this->parseXmlArray($xml_response);
  804. $cData=$gCustom['http://checkout.google.com/schema/2']['SHOPPING-CART']['ITEMS']['ITEM']['MERCHANT-PRIVATE-ITEM-DATA'];
  805. $ipnData=explode("^",$cData);
  806. $userId=$ipnData['0'];
  807. $lastId=$ipnData['1'];
  808. $invoice=$ipnData['2'];
  809. $ticket=$ipnData['3'];
  810. $totalPay=$ipnData['4'];
  811. }
  812. }
  813. */
  814. }
  815. //checking
  816. function featuredsuccess() {
  817. $is_featured = 1;
  818. $productId=0;
  819. if(isset($this->params['url']['lid']))
  820. $productId=base64_decode($this->params['url']['lid']);
  821. if($productId==0) {
  822. //_______________________________________________IPN data received from PAYPAL and GOOGLE payment methods
  823. $paypal=0;
  824. if (isset($_POST['payment_gross']) && ($_POST['payment_gross'])!="") {
  825. $paypal=1;
  826. $totalPay=$_POST['payment_gross'];
  827. $custom=explode("^",$_POST['custom']);
  828. $userId=$custom['0'];
  829. $sellerId=$custom['1'];
  830. $isAdmin=$custom['2'];
  831. $rdPage=$custom['3'];
  832. $invoice=$custom['4'];
  833. $transactionId=$custom['5'];
  834. $ticket=$custom['6'];
  835. $productId=$custom['7'];
  836. }
  837. //This section is used to catch from GOOGLE IPN data
  838. if(!$paypal) {
  839. //this section is used to update from google IPN data
  840. $xml_response = isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:file_get_contents("php://input");
  841. if($xml_response) {
  842. $gCustom=$this->parseXmlArray($xml_response);
  843. $cData=$gCustom['http://checkout.google.com/schema/2']['SHOPPING-CART']['ITEMS']['ITEM']['MERCHANT-PRIVATE-ITEM-DATA'];
  844. $ipnData=explode("^",$cData);
  845. $userId=$ipnData['0'];
  846. $sellerId=$ipnData['1'];
  847. $isAdmin=$ipnData['2'];
  848. $rdPage=$ipnData['3'];
  849. $invoice=$ipnData['4'];
  850. $transactionId=$ipnData['5'];
  851. $totalPay=$ipnData['6'];
  852. $ticket=$ipnData['7'];
  853. $productId=$ipnData['8'];
  854. }
  855. }
  856. }else {
  857. $userId = $_SESSION['UserId'];
  858. $totalPay = 0;
  859. $ticket = $this->createTransactionNumber('SPTT');
  860. $is_featured = 0;
  861. }
  862. //________________________________________________XOIMAGE DATABASE UPDATION SECTION
  863. //update featured_time
  864. $featured_time = NULL;
  865. if($is_featured==1){
  866. $result = $this->getConfigAmount('creative featured days');
  867. $featureddays = $result['config_value'];
  868. $featured_time = date('Y-m-d G:i:s', strtotime("+".$featureddays." day"));
  869. }
  870. $queryCreativeFavorites=mysql_query("
  871. UPDATE creative_favorites
  872. SET is_featured='$is_featured',is_temp='0', featured_time='".$featured_time."'
  873. WHERE user_id='".$userId."' AND id='".$productId."'") or die("Error on line : ".__LINE__.mysql_error());
  874. if(isset($transactionId)) {
  875. //UPDATE date on TRANSACTION_CREATIVE TABLE
  876. $queryUpdateTransactionCreative="
  877. UPDATE transaction_creatives
  878. SET pay_status='1',invoice='".$invoice."'
  879. WHERE id='".$transactionId."' AND user_id='".$userId."'";
  880. mysql_query($queryUpdateTransactionCreative) or die("Error on line : ".__LINE__.mysql_error());
  881. //UPDATE data to the CREATIVE_CARTS TABLE after successful transaction
  882. $queryUpdateCreativeCart="
  883. UPDATE creative_carts
  884. SET pay_status='1', total_price='".$totalPay."'
  885. WHERE user_id='".$userId."' AND pay_status='0' AND transaction_creative_id='".$transactionId."' ";
  886. mysql_query($queryUpdateCreativeCart) or die("Error on line : ".__LINE__.mysql_error());
  887. }
  888. //____________________________________________________TRANSACTION LOG MANAGEMENT_____________________________________
  889. $userDetails=$this->getUserDetails($userId);
  890. $scrapDetails=$this->scrapDetails($productId);
  891. if(isset($invoice))
  892. $this->set('invoice',$invoice);
  893. $this->set('ticket',$ticket);
  894. $this->set('totalPay',$totalPay);
  895. //ticket
  896. $ticketData = $this->Creative_tickets->findByCreative_favorites_id($productId);
  897. if(!$ticketData) {
  898. $ticketData['Creative_tickets']['user_id'] = $userId;
  899. $ticketData['Creative_tickets']['creative_favorites_id'] = $productId;
  900. $ticketData['Creative_tickets']['ticket_number'] = $ticket;
  901. $ticketData['Creative_tickets']['status'] = 'awaiting';
  902. $this->Creative_tickets->create();
  903. $this->Creative_tickets->save($ticketData);
  904. //____________________________________________________MAIL MANAGEMENT________________________________________________
  905. //this mailing code is here so that it fires just once.
  906. //mail sent to the user personal account
  907. $this->Sendmail->Mail();
  908. $this->Sendmail->From(FROMMAIL);
  909. if(isset($userDetails['email'])) {
  910. $this->Sendmail->To($userDetails['email']);
  911. //$this->Sendmail->Cc("sujoy@navsoft.in");
  912. //$this->Sendmail->Cc("amarjit@navsoft.in");
  913. //$this->Sendmail->Bcc( "someoneelse@somewhere.fr");
  914. $subject="XOimages - Scrapfoto Ticket ".$ticket;
  915. $this->Sendmail->Subject($subject);
  916. $this->set("ticket_number",$ticket);
  917. if(isset($invoice)) {
  918. $featuredAmount=$this->getConfigAmount('creative featured');
  919. $this->set('featurefee', $featuredAmount['config_value']);
  920. }
  921. $this->Sendmail->layout='email';
  922. $this->Sendmail->view='mail_ticket';
  923. $this->Sendmail->startup($this);
  924. $messageBody=$this->Sendmail->bodyText();
  925. $this->Sendmail->Body($messageBody); // set the body
  926. $this->Sendmail->Priority(1) ; // set the priority to Low
  927. $this->Sendmail->Send(); // send the mail
  928. //mail sent to the user mail account in the system
  929. $sender=1;
  930. $receiver=$userId;
  931. $this->senderMail($sender,$receiver,$subject,$messageBody);
  932. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  933. }
  934. }else {
  935. $ticket = $ticketData['Creative_tickets']['ticket_number'];
  936. }
  937. //invoice
  938. if(isset($invoice)) {
  939. $downloadimg=$this->getCartImages($userId,$transactionId);
  940. $zipfilename = 'scrapblogimg'.$transactionId.$userId.'.zip';
  941. //UPDATE transaction_creatives with the scrapfoto filename$zipfilename
  942. mysql_query("
  943. UPDATE transaction_creatives
  944. SET scrapfoto_file='".$zipfilename."'
  945. WHERE id='".$transactionId."' AND user_id='".$userId."'") or die("Error on line - ".__LINE__.mysql_error());
  946. ;
  947. $downloadimgs = array();
  948. $Imgdestination='';
  949. foreach($downloadimg as $img) {
  950. $arr = explode('/', $img);
  951. $downloadimgs[] = $arr[count($arr)-1];
  952. $Imgdestination = '../'.substr($img, 0, - strlen($arr[count($arr)-1]));
  953. }
  954. $Imgdestination = realpath($Imgdestination).'/';
  955. $zipdestination = realpath('../app/webroot/creativezone/downloadscraps/').'/';
  956. $this->Zipfile->addFiles($downloadimgs,$Imgdestination); //array of files
  957. $this->Zipfile->output($zipfilename,$zipdestination);
  958. $queryXouserTransactions=mysql_query("SELECT * FROM xouser_transactions WHERE transaction_head='scrapfoto' AND transaction_title='feature' AND invoice_id='".$transactionId."'");
  959. if(mysql_num_rows($queryXouserTransactions)<=0) {
  960. $transactionDesc="ScrapFOTO - scraps featured";
  961. $transactionHead="scrapfoto";
  962. $transactionTitle="feature";
  963. $invoiceId=$transactionId;
  964. $statusoffee = "nontransactionfee";
  965. $lastInsertId=$this->transactionMaster($transactionDesc,$transactionHead,$transactionTitle,$invoice,$invoiceId);
  966. $this->transactionDetail($userId,$totalPay,'-1',$lastInsertId,1,$statusoffee,0,'finished'); //charged//this code is changed on 7th January 2010(statusfee added as well as paymentstatus value 'finished' added---finished is not in used now.)
  967. //$this->transactionDetail($userId,$totalPay,'+1',$lastInsertId,1); //paid//this code is blocked on 7th January 2010
  968. //____________________________________________________MAIL MANAGEMENT________________________________________________
  969. //this mailing code is here so that it fires just once.
  970. //mail sent to the user personal account
  971. if(isset($userDetails['email'])) {
  972. $this->Sendmail->Mail();
  973. $this->Sendmail->From(FROMMAIL);
  974. $this->Sendmail->To($userDetails['email']);
  975. //$this->Sendmail->Cc("sujoy@navsoft.in");
  976. //$this->Sendmail->Cc("amarjit@navsoft.in");
  977. //$this->Sendmail->Bcc( "someoneelse@somewhere.fr");
  978. $subject="XOimages - ScrapFoto Invoice ".$invoice;
  979. $this->Sendmail->Subject($subject);
  980. $this->set('tranId', $invoiceId);
  981. $featuredAmount=$this->getConfigAmount('creative featured');
  982. $this->set('featurefee', $featuredAmount['config_value']);
  983. $this->Sendmail->layout='email';
  984. $this->Sendmail->view='mail_scrapfeature';
  985. $this->Sendmail->startup($this);
  986. $messageBody=$this->Sendmail->bodyText();
  987. $this->Sendmail->Body($messageBody); // set the body
  988. $this->Sendmail->Priority(1) ; // set the priority to Low
  989. $this->Sendmail->Send(); // send the mail
  990. //mail sent to the user mail account in the system
  991. $sender=1;
  992. $receiver=$userId;
  993. $this->senderMail($sender,$receiver,$subject,$messageBody);
  994. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  995. }
  996. }
  997. }
  998. $this->layout = 'creativedetail';
  999. $this->creativeType();
  1000. $this->countFavCart();
  1001. $this->getRankScrap();
  1002. $this->getFeaturedScrap();
  1003. $this->getPublicScrap();
  1004. $this->render('featuredsuccess','creativedetail');
  1005. }
  1006. //test
  1007. function mail_ticket($ticket) {
  1008. $this->layout = 'email';
  1009. $this->set("ticket_number",$ticket);
  1010. $featuredAmount=$this->getConfigAmount('creative featured');
  1011. $this->set('featurefee', $featuredAmount['config_value']);
  1012. }
  1013. //test
  1014. function mail_scrapfeature($tranId) {
  1015. $this->layout = 'email';
  1016. $this->set("tranId",$tranId);
  1017. $featuredAmount=$this->getConfigAmount('creative featured');
  1018. $this->set('featurefee', $featuredAmount['config_value']);
  1019. }
  1020. function scrapDetails($id) {
  1021. $queryCreativeFavorites=mysql_query("SELECT * FROM creative_favorites WHERE id='".$id."'");
  1022. return $fetchCreativeFavorites=mysql_fetch_assoc($queryCreativeFavorites);
  1023. }
  1024. function getUserCreativeSalesTax($stateId) {
  1025. $queryCreativeSaletax=mysql_query("
  1026. SELECT tax
  1027. FROM creative_saletax CS WHERE CS.state_id='".$stateId."'") or die("Error on line ".__LINE__.mysql_error());
  1028. $fetchCreativeSaletax=mysql_fetch_assoc($queryCreativeSaletax);
  1029. return $fetchCreativeSaletax['tax'];
  1030. }
  1031. //checking
  1032. function chargecouponcode() {
  1033. //cart deatils
  1034. $this->getCartDetails();
  1035. //sale tax
  1036. $stateId=0;
  1037. $saleTax=0;
  1038. if(isset($this->params['url']['orderBy']))
  1039. $stateId=$this->params['url']['orderBy'];
  1040. if(isset($this->params['pass']['0']))
  1041. $stateId=$this->params['pass']['0'];
  1042. $saleTax=$this->getUserCreativeSalesTax($stateId);
  1043. $this->set("saleTax",$saleTax);
  1044. $this->set("stateId",$stateId);
  1045. //Coupon code
  1046. $couponCode=$this->params['pass']['1'];
  1047. $this->set("coupon",$couponCode);
  1048. $curDate=date("Y-m-d");
  1049. $couponValue=0;
  1050. $qry="SELECT coupon_value FROM creative_coupon
  1051. WHERE coupon_code='".$couponCode."' AND '$curDate' BETWEEN coupon_from AND coupon_to AND blocked='0'";
  1052. $q1=mysql_query($qry);
  1053. if(mysql_num_rows($q1)>0) {
  1054. $rw=mysql_fetch_assoc($q1);
  1055. $couponValue=$rw['coupon_value'];
  1056. }
  1057. //payment details
  1058. //check if buy template then get payment of user create artist
  1059. $tmpImg=0;
  1060. if(isset($_SESSION['buyTemplate']['tmpId']))
  1061. $tmpImg= $this->templateDetail($_SESSION['buyTemplate']['tmpId']);
  1062. if($tmpImg>0) {
  1063. $fav = $this->Creative_favorites->findById($tmpImg);
  1064. $fetchAdminPaymentSetup=$this->getPaymentMethodsUsers($fav['Creative_favorites']['user_id']); // that means payment will go to the user paymenbt id
  1065. $this->set('sellerId',$fav['Creative_favorites']['user_id']);
  1066. }else {
  1067. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  1068. $this->set('sellerId',1);
  1069. }
  1070. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  1071. $this->set("couponValue",$couponValue);
  1072. $this->set("saleTax",$saleTax);
  1073. $this->render("couponcharge","ajax");
  1074. }
  1075. function feature_chargecouponcode() {
  1076. $featuredAmount=$this->getConfigAmount('creative featured');
  1077. $totalAmount = $featuredAmount['config_value'];
  1078. //sale tax
  1079. $stateId=0;
  1080. $saleTax=0;
  1081. if(isset($this->params['url']['orderBy']))
  1082. $stateId=$this->params['url']['orderBy'];
  1083. if(isset($this->params['pass']['0']))
  1084. $stateId=$this->params['pass']['0'];
  1085. $saleTax=$this->getUserCreativeSalesTax($stateId);
  1086. $this->set("saleTax",$saleTax);
  1087. $this->set("stateId",$stateId);
  1088. //Coupon code
  1089. $couponCode=$this->params['pass']['1'];
  1090. $this->set("coupon",$couponCode);
  1091. $curDate=date("Y-m-d");
  1092. $couponValue=0;
  1093. $qry="SELECT coupon_value FROM creative_coupon
  1094. WHERE coupon_code='".$couponCode."' AND '$curDate' BETWEEN coupon_from AND coupon_to AND blocked='0'";
  1095. $q1=mysql_query($qry);
  1096. if(mysql_num_rows($q1)>0) {
  1097. $rw=mysql_fetch_assoc($q1);
  1098. $couponValue=$rw['coupon_value'];
  1099. }
  1100. //payment details
  1101. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  1102. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  1103. $this->set("couponValue",$couponValue);
  1104. $this->set("saleTax",$saleTax);
  1105. $this->set("totalAmount",$totalAmount);
  1106. $this->render("feature_chargecouponcode","ajax");
  1107. }
  1108. function getcheckoutcity() {
  1109. $this->checkSession();
  1110. $usrDetail=$this->getUserDetails($_SESSION['UserId']);
  1111. $this->set("UserDtl",$usrDetail);
  1112. //$this->set("arg",$this->params['url']);
  1113. $city=$this->getCityList($this->params['url']['orderBy']);
  1114. $this->set("billingCity",$city);
  1115. $this->set("divType",$this->params['url']['s']);
  1116. $this->getCartDetails();
  1117. //sale tax
  1118. $stateId=0;
  1119. $saleTax=0;
  1120. if(isset($this->params['url']['orderBy']))
  1121. $stateId=$this->params['url']['orderBy'];
  1122. if(isset($this->params['pass']['0']))
  1123. $stateId=$this->params['pass']['0'];
  1124. $saleTax=$this->getUserCreativeSalesTax($stateId);
  1125. $this->set("saleTax",$saleTax);
  1126. $this->set("stateId",$stateId);
  1127. //Coupon code
  1128. $couponCode=$this->params['pass']['1'];
  1129. $this->set("coupon",$couponCode);
  1130. $curDate=date("Y-m-d");
  1131. $couponValue=0;
  1132. $qry="SELECT coupon_value FROM creative_coupon
  1133. WHERE coupon_code='".$couponCode."' AND '$curDate' BETWEEN coupon_from AND coupon_to AND blocked='0'";
  1134. $q1=mysql_query($qry);
  1135. if(mysql_num_rows($q1)>0) {
  1136. $rw=mysql_fetch_assoc($q1);
  1137. $couponValue=$rw['coupon_value'];
  1138. }
  1139. //payment details
  1140. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  1141. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  1142. $this->set("couponValue",$couponValue);
  1143. $this->set("saleTax",$saleTax);
  1144. $this->render("checkoutcitylist","ajax");
  1145. }
  1146. function getcheckoutstate() {
  1147. $this->checkSession();
  1148. $usrDetail=$this->getUserDetails($_SESSION['UserId']);
  1149. $this->set("UserDtl",$usrDetail);
  1150. //$this->set("arg",$this->params['url']);
  1151. $state=$this->getStateList($this->params['url']['orderBy']);
  1152. $this->set("stateBList",$state);
  1153. $this->set("divType",$this->params['url']['c']);
  1154. $this->render("checkoutstatelist","ajax");
  1155. }
  1156. function getUserDetails($user_id=null) {
  1157. if($user_id==null)
  1158. $user_id = $_SESSION['UserId'];
  1159. $coutryList=array();
  1160. $countryList['0']="Select a country";
  1161. $qry = mysql_query("SELECT * FROM countries");
  1162. while($country = mysql_fetch_array($qry)) {
  1163. $countryList[$country['id']]=$country['country_name'];
  1164. }
  1165. $qry2=mysql_query("SELECT * FROM user_details WHERE user_id=".$user_id);
  1166. $rowQry=mysql_fetch_assoc($qry2);
  1167. $this->set("UserDtl",$rowQry);
  1168. $saleTax=$this->getUserCreativeSalesTax($rowQry['state']);
  1169. $this->set("saleTax",$saleTax);
  1170. $countryList=$this->getCountryList();
  1171. $bList=$this->getStateList($rowQry['c_id']);
  1172. $SList=$this->getStateList($rowQry['shipc_id']);
  1173. $billingCity=$this->getCityList($rowQry['state']);
  1174. $this->set("billingCity",$billingCity);
  1175. $this->set("stateBList",$bList);
  1176. $this->set("stateSList",$SList);
  1177. $this->set("countryList",$countryList);
  1178. return $rowQry;
  1179. }
  1180. function getCreativeState($conId) {
  1181. $stateSList=array("0"=>"Select State");
  1182. $qry3 = mysql_query("SELECT * FROM state WHERE c_id='".$conId."'");
  1183. while($state = mysql_fetch_array($qry3)) {
  1184. $stateSList[$state['id']]=$state['Name'];
  1185. }
  1186. $this->set("stateBList",$stateSList);
  1187. }
  1188. function getstate() {
  1189. $this->getCreativeState($this->params['url']['orderBy']);
  1190. $this->render("creativestate","ajax");
  1191. }
  1192. function creative_cart() {
  1193. $this->checkSession();
  1194. $this->pageTitle = 'ScrapFOTO&trade; - My Cart';
  1195. $this->layout = 'creativehome';
  1196. $this->creativeType();
  1197. $this->getPublicScrap();
  1198. $cartCount=$this->countFavCart();
  1199. if($cartCount<=0) {
  1200. $this->redirect("/creativezones/creative_favorite");
  1201. die();
  1202. }
  1203. $tmpImg=0;
  1204. if(isset($_SESSION['buyTemplate']['tmpId']))
  1205. $tmpImg= $this->templateDetail($_SESSION['buyTemplate']['tmpId']);
  1206. //Initializing all the bradcamp back again so that it all starts all over again
  1207. $this->set("filename","creative_cart"); //filename should contain the name of the file that should be selected
  1208. $this->set("nextpage","checkout");
  1209. //_________________________________________________________________________________________________
  1210. $this->set("recenttype","creative_favorite");
  1211. $this->getCartDetails();
  1212. $this->getUserDetails();
  1213. //$this->getUserCreativeSalesTax($_SESSION['UserId']);
  1214. ############################################## CART CODE #################################
  1215. if(isset($this->params['url']['act']) && $this->params['url']['act']=="update") {
  1216. $cartsql2 ="
  1217. SELECT SUM(CM.price*CM.qty) as totValue
  1218. FROM creative_carts CM,creative_cart_details CD
  1219. WHERE CM.id=CD.creative_cart_id AND CM.pay_status='0' AND CM.user_id='".$_SESSION['UserId']."' AND CM.ssn_id='".session_id()."'";
  1220. $rec=mysql_query($cartsql2);
  1221. $resultSet=mysql_fetch_assoc($rec);
  1222. $this->set("totalValue",$resultSet['totValue']);
  1223. $this->set("arg",$this->params['url']);
  1224. $this->render("mycart2","ajax");
  1225. }
  1226. if(isset($this->params['url']['act']) && $this->params['url']['act']=="saveupdate") {
  1227. $cartId=$this->params['url']['cid'];
  1228. $i=$this->params['url']['i'];
  1229. //mysql_query("UPDATE backdrop_cart SET quantity='".$this->data['Backdrop']['qty'.$i]."' WHERE id='".$cartId."'");
  1230. $cartsql2 ="
  1231. SELECT SUM(CM.price*CM.qty) as totValue
  1232. FROM creative_carts CM,creative_cart_details CD
  1233. WHERE CM.id=CD.creative_cart_id AND CM.pay_status='0' AND CM.user_id='".$_SESSION['UserId']."' AND CM.ssn_id='".session_id()."'";
  1234. $rec=mysql_query($cartsql2);
  1235. $resultSet=mysql_fetch_assoc($rec);
  1236. $this->set("totalValue",$resultSet['totValue']);
  1237. $this->set("qty",$this->data['Creativezone']['qty'.$i]);
  1238. $this->set("arg",$this->params['url']);
  1239. $this->set("argForm",$this->params['form']);
  1240. $this->render("mycart2","ajax");
  1241. }
  1242. if(isset($this->params['url']['action']) && $this->params['url']['action']=="deleteCartitem") {
  1243. if(isset($this->params['url']['cartid'])) {
  1244. $cartId=base64_decode($this->params['url']['cartid']);
  1245. $delCartItem = "DELETE from creative_carts where id='".$cartId."' AND ssn_id='".session_id()."' AND pay_status='0' AND user_id='".$_SESSION['UserId']."'";
  1246. mysql_query($delCartItem);
  1247. }
  1248. else {
  1249. if(isset($this->params['url']['cartuserid'])) {
  1250. $cartBlockuser=base64_decode($this->params['url']['cartuserid']);
  1251. $delCartItem = "DELETE FROM creative_carts WHERE ssn_id='".session_id()."' AND pay_status='0' AND user_id='".$_SESSION['UserId']."' AND product_name IN (SELECT title FROM creative_favorites WHERE user_id='".$cartBlockuser."' AND is_temp='0' AND is_blocked='0')";
  1252. mysql_query($delCartItem) or die("Error on line - ".__LINE__.mysql_error());
  1253. }
  1254. }
  1255. }
  1256. if(isset($this->params['url']['action']) && $this->params['url']['action']=="deleteCartitem") {
  1257. $this->render("myupdatedcart","ajax");
  1258. }
  1259. ###########################################
  1260. //check if buy template then get payment of user create artist
  1261. if($tmpImg>0) {
  1262. $fav = $this->Creative_favorites->findById($tmpImg);
  1263. $fetchAdminPaymentSetup=$this->getPaymentMethodsUsers($fav['Creative_favorites']['user_id']); // that means payment will go to the user paymenbt id
  1264. $this->set('sellerId',$fav['Creative_favorites']['user_id']);
  1265. }else {
  1266. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  1267. $this->set('sellerId',1);
  1268. }
  1269. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  1270. }
  1271. function pcreative_cart() {
  1272. $this->checkSession();
  1273. $this->pageTitle = 'Creative - My Cart';
  1274. $this->layout = 'creativedetail';
  1275. $this->creativeType();
  1276. $this->getPublicScrap();
  1277. //This ct variable comes from INDEX page and CREATIVETEMPLATE page
  1278. $id=0;
  1279. if(isset($this->params['url']['ct']))
  1280. $id=base64_decode($this->params['url']['ct']);
  1281. //This ct variable comes from CREATIVETEMPLATE page
  1282. $tmpImg=0;
  1283. if(isset($this->params['url']['tmp']))
  1284. $tmpImg=base64_decode($this->params['url']['tmp']);
  1285. $this->set("cType",$id);
  1286. $this->set("cTemplate",$tmpImg);
  1287. $this->countFavCart();
  1288. //Initializing all the bradcamp back again so that it all starts all over again
  1289. $this->set("filename","creative_cart"); //filename should contain the name of the file that should be selected
  1290. $_SESSION['bradcamp_creative'][80]=$this->params['action']; //we are passing the name of the file to keep track which step is visited
  1291. $this->set("nextpage","checkout");
  1292. //_________________________________________________________________________________________________
  1293. $this->set("recenttype","creative_favorite");
  1294. $this->getCartDetails();
  1295. ############################################## CART CODE #################################
  1296. $queryCreativeCarts=mysql_query("
  1297. SELECT CM.id,CM.product_name,CM.price,CM.qty,CD.imagename,(CM.price*CM.qty) as subTotal
  1298. FROM creative_carts CM,creative_cart_details CD
  1299. WHERE CM.id=CD.creative_cart_id AND CM.pay_status='0' AND CM.user_id='".$_SESSION['UserId']."' AND CM.ssn_id='".session_id()."'
  1300. GROUP BY CM.id");
  1301. if(isset($this->params['url']['act']) && $this->params['url']['act']=="update") {
  1302. $cartsql2 ="
  1303. SELECT SUM(CM.price*CM.qty) as totValue
  1304. FROM creative_carts CM,creative_cart_details CD
  1305. WHERE CM.id=CD.creative_cart_id AND CM.pay_status='0' AND CM.user_id='".$_SESSION['UserId']."' AND CM.ssn_id='".session_id()."'";
  1306. $rec=mysql_query($cartsql2);
  1307. $resultSet=mysql_fetch_assoc($rec);
  1308. $this->set("totalValue",$resultSet['totValue']);
  1309. $this->set("arg",$this->params['url']);
  1310. $this->render("mycart2","ajax");
  1311. }
  1312. if(isset($this->params['url']['act']) && $this->params['url']['act']=="saveupdate") {
  1313. $cartId=$this->params['url']['cid'];
  1314. $i=$this->params['url']['i'];
  1315. //mysql_query("UPDATE backdrop_cart SET quantity='".$this->data['Backdrop']['qty'.$i]."' WHERE id='".$cartId."'");
  1316. $cartsql2 ="
  1317. SELECT SUM(CM.price*CM.qty) as totValue
  1318. FROM creative_carts CM,creative_cart_details CD
  1319. WHERE CM.id=CD.creative_cart_id AND CM.pay_status='0' AND CM.user_id='".$_SESSION['UserId']."' AND CM.ssn_id='".session_id()."'";
  1320. $rec=mysql_query($cartsql2);
  1321. $resultSet=mysql_fetch_assoc($rec);
  1322. $this->set("totalValue",$resultSet['totValue']);
  1323. $this->set("qty",$this->data['Creativezone']['qty'.$i]);
  1324. $this->set("arg",$this->params['url']);
  1325. $this->set("argForm",$this->params['form']);
  1326. $this->render("mycart2","ajax");
  1327. }
  1328. if(isset($this->params['url']['action']) && $this->params['url']['action']=="deleteCartitem") {
  1329. if(isset($this->params['url']['cartid'])) {
  1330. $cartId=base64_decode($this->params['url']['cartid']);
  1331. $delCartItem = "DELETE from creative_carts where id='".$cartId."' AND ssn_id='".session_id()."' AND pay_status='0' AND user_id='".$_SESSION['UserId']."'";
  1332. mysql_query($delCartItem);
  1333. }
  1334. else {
  1335. if(isset($this->params['url']['cartuserid'])) {
  1336. $cartBlockuser=base64_decode($this->params['url']['cartuserid']);
  1337. $delCartItem = "DELETE FROM creative_carts WHERE ssn_id='".session_id()."' AND pay_status='0' AND user_id='".$_SESSION['UserId']."' AND product_name IN (SELECT title FROM creative_favorites WHERE user_id='".$cartBlockuser."' AND is_temp='0' AND is_blocked='0')";
  1338. mysql_query($delCartItem) or die("Error on line - ".__LINE__.mysql_error());
  1339. }
  1340. }
  1341. }
  1342. if(isset($_SESSION['UserId'])) {
  1343. $cartsql = "
  1344. SELECT CM.id,Cfav.id as favid,CM.product_name,Creativedetail.imagename,
  1345. CM.qty,CM.price ,(CM.price*CM.qty) as subtotal
  1346. from creative_carts CM
  1347. LEFT JOIN creative_cart_details Creativedetail ON CM.id =Creativedetail.creative_cart_id
  1348. LEFT JOIN creative_favorites Cfav ON CM.product_name = Cfav.title
  1349. LEFT JOIN creative_template_pages ctemppage ON Cfav.id=ctemppage.id
  1350. where
  1351. CM.user_id='".$_SESSION['UserId']."' AND CM.ssn_id='".session_id()."'and CM.pay_status='0' ";
  1352. $this->set('mycartsql',$cartsql);
  1353. $newcartsql ="
  1354. SELECT ifnull( Buser.username, 'NA') AS username,
  1355. Cfav.id , Cfav.user_id,
  1356. COUNT( Cfav.title) as creative_count
  1357. FROM creative_carts Creativecart
  1358. LEFT JOIN creative_favorites Cfav ON Creativecart.product_name = Cfav.title
  1359. LEFT JOIN users Buser ON ( Cfav.user_id = Buser.id )
  1360. WHERE Creativecart.user_id = '".$_SESSION['UserId']."'
  1361. AND Creativecart.ssn_id = '".session_id()."'
  1362. AND Creativecart.pay_status = '0'
  1363. GROUP BY Cfav.user_id
  1364. ";
  1365. $this->set('newmycartsql',$newcartsql);
  1366. }
  1367. if(isset($this->params['url']['action']) && $this->params['url']['action']=="deleteCartitem") {
  1368. $this->render("myupdatedcart","ajax");
  1369. }
  1370. ###########################################
  1371. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  1372. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  1373. }
  1374. //checking
  1375. function getCartImages($userId,$tranId,$isThumb=false) {
  1376. $downloadimg=array();
  1377. $getYearBookImg=mysql_query("
  1378. SELECT CF.fileZip, CF.fileThumb2
  1379. FROM creative_carts C,creative_cart_details CD, creative_favorites as CF
  1380. WHERE C.id=CD.creative_cart_id AND CF.id=CD.creative_favorite_id AND C.user_id='".$userId."' AND C.pay_status='1' AND transaction_creative_id='".$tranId."'
  1381. ") or die(mysql_error());
  1382. while($rwYearbookImg=mysql_fetch_assoc($getYearBookImg)) {
  1383. if($isThumb)
  1384. array_push($downloadimg,$rwYearbookImg['fileThumb2']);
  1385. else
  1386. array_push($downloadimg,$rwYearbookImg['fileZip']);
  1387. }
  1388. return $downloadimg;
  1389. }
  1390. //checking
  1391. function checkout() {
  1392. $this->checkSession();
  1393. $this->countFavCart();
  1394. $this->layout = 'previewpaymemnt';
  1395. $this->render("paymentback");
  1396. $totalAmount=$this->data['creative']['totalAmount'];
  1397. $sellerId=$this->data['creative']['sellerId'];
  1398. //$rdPage refers to function success
  1399. $rdPage=$this->data['creative']['rdpage'];
  1400. $isAdmin=1;
  1401. //If user purchases his own scraps then the payment will go to admin
  1402. //If the user purchases scraps of other users then the payment will go to that other users
  1403. if($sellerId==1) {
  1404. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  1405. }
  1406. else {
  1407. $isAdmin=0;
  1408. $fetchAdminPaymentSetup=$this->getPaymentMethodsUsers($sellerId);
  1409. }
  1410. //UPDATE USERS ADDRESS
  1411. if(!empty($this->data)) {
  1412. if(isset($this->data['creativezones']['B']) && ($this->data['creativezones']['B'])!="") {
  1413. $updateUser="
  1414. UPDATE user_details
  1415. SET
  1416. address='".$this->data['creativezones']['Baddress']."',city='".$this->data['creativezones']['Bcity']."',
  1417. zip='".$this->data['creativezones']['Bzip']."',c_id='".$this->params['form']['creativezonesBcountry']."'
  1418. ,state='".$this->params['form']['creativezonesBstate']."'
  1419. WHERE user_id=".$_SESSION['UserId'];
  1420. mysql_query($updateUser);
  1421. }
  1422. }
  1423. $feature = isset($this->data['creativezones']['feature']);
  1424. if($feature) {
  1425. //create creative_carts
  1426. mysql_query("DELETE FROM creative_carts WHERE pay_status='0' AND user_id='".$_SESSION['UserId']."'");
  1427. mysql_query("INSERT INTO
  1428. creative_carts(user_id,cart_name,transaction_creative_id,pay_status)
  1429. VALUES('".$_SESSION['UserId']."','Feature fee','0','0')") or die("Error on line : ".__LINE__.mysql_error());
  1430. $cart_id=mysql_insert_id();
  1431. $productId = $this->data['creativezones']['lastId'];
  1432. $featuredAmount=$this->getConfigAmount('creative featured');
  1433. $price = $featuredAmount['config_value'];
  1434. mysql_query("INSERT INTO creative_cart_details SET creative_cart_id='$cart_id' ,creative_favorite_id='$productId', product_name='Feature fee',price='$price',qty='1'");
  1435. }
  1436. $transactionfee = isset($this->data['creativezones']['transactionfee']);
  1437. if(!$transactionfee) {
  1438. //insert data to the TRANSACTION_CREATIVES TABLE after successful transaction
  1439. mysql_query("INSERT INTO
  1440. transaction_creatives(user_id,seller_id,total_amount,is_admin)
  1441. VALUES('".$_SESSION['UserId']."','".$sellerId."','".$totalAmount."','".$isAdmin."')") or die("Error on line : ".__LINE__.mysql_error());
  1442. $lastTransactionId=mysql_insert_id();
  1443. //UPDATE CART
  1444. mysql_query("
  1445. UPDATE creative_carts
  1446. SET
  1447. coupon='".$this->data['creativezones']['couponprice']."',
  1448. saletax='".$this->data['creativezones']['saletax']."',
  1449. transaction_creative_id='".$lastTransactionId."'
  1450. WHERE pay_status='0' AND user_id='".$_SESSION['UserId']."'");
  1451. $invoice = $this->createTransactionNumber('SP');
  1452. $ticket = $this->createTransactionNumber('SPTT');
  1453. }else {
  1454. $invoice = $this->data['creativezones']['lastId'];
  1455. }
  1456. $zero =str_repeat('0',(5-strlen($_SESSION['UserId'])));
  1457. $userId=$zero.$_SESSION['UserId'];
  1458. if(isset($this->data['Event']['radiobutton'])) {
  1459. if($this->data['Event']['radiobutton']=="paypal") {
  1460. $this->invoice=$invoice;
  1461. $this->amountPay=$totalAmount;
  1462. $this->merchantEmail=$fetchAdminPaymentSetup['paypal_email'];
  1463. if($transactionfee) {
  1464. $this->invoice='TF'.$invoice;
  1465. $this->itemName="ScrapFOTO&trade; Transaction Fee";
  1466. $this->returnUrl=FULL_BASE_URL.$this->webroot."creativezones/transactionfee_success";
  1467. $this->notifyUrl=FULL_BASE_URL.$this->webroot."creativezones/transactionfee_payment_notify";
  1468. $this->custom=$_SESSION['UserId']."^".$sellerId."^".$isAdmin."^".$rdPage."^".$invoice;
  1469. }else if($feature) {
  1470. $this->itemName="ScrapFOTO&trade; Featured";
  1471. $this->returnUrl=FULL_BASE_URL.$this->webroot."creativezones/featuredsuccess";
  1472. $this->notifyUrl=FULL_BASE_URL.$this->webroot."creativezones/featured_payment_notify";
  1473. $this->custom=$_SESSION['UserId']."^".$sellerId."^".$isAdmin."^".$rdPage."^".$invoice."^".$lastTransactionId."^".$ticket."^".$productId;
  1474. }else {
  1475. $this->itemName="ScrapFOTO&trade; Image download";
  1476. $this->returnUrl=FULL_BASE_URL.$this->webroot."creativezones/".$rdPage."?tr=".base64_encode($lastTransactionId);//DOMAIN
  1477. $this->notifyUrl=FULL_BASE_URL.$this->webroot."creativezones/checkout_notify";
  1478. $this->custom=$_SESSION['UserId']."^".$sellerId."^".$isAdmin."^".$rdPage."^".$invoice."^".$lastTransactionId;
  1479. }
  1480. $this->paypal();
  1481. }
  1482. if($this->data['Event']['radiobutton']=="google") {
  1483. $adminPayment=$fetchAdminPaymentSetup['gcheckout_email'];
  1484. $adminPaymentDetails=explode("break",$adminPayment);
  1485. $this->Gcheckout->gMerchantId=$adminPaymentDetails['0'];
  1486. $this->Gcheckout->gMerchantKey=$adminPaymentDetails['1'];
  1487. $this->Gcheckout->gQuantity=1;
  1488. $this->Gcheckout->gPrice=$totalAmount;
  1489. if($feature) {
  1490. $this->Gcheckout->gItemName="ScrapFOTO&trade; Featured";
  1491. $this->Gcheckout->gItemDesc="ScrapFOTO&trade; Featured";
  1492. $this->Gcheckout->gReturnUrl=FULL_BASE_URL.$this->webroot."creativezones/featuredsuccess";
  1493. $this->Gcheckout->gNotifyUrl=FULL_BASE_URL.$this->webroot."creativezones/featured_payment_notify";
  1494. $this->Gcheckout->customData=$_SESSION['UserId']."^".$sellerId."^".$isAdmin."^".$rdPage."^".$invoice."^".$lastTransactionId."^".$totalAmount."^".$ticket."^".$productId;
  1495. }else if($transactionfee) {
  1496. $this->Gcheckout->gItemName="ScrapFOTO&trade; Transaction Fee";
  1497. $this->Gcheckout->gItemDesc="ScrapFOTO&trade; Transaction Fee";
  1498. $this->Gcheckout->gReturnUrl=FULL_BASE_URL.$this->webroot."creativezones/transactionfee_success";
  1499. $this->Gcheckout->gNotifyUrl=FULL_BASE_URL.$this->webroot."creativezones/transactionfee_payment_notify";
  1500. $this->Gcheckout->customData=$_SESSION['UserId']."^".$sellerId."^".$isAdmin."^".$rdPage."^".$invoice."^".$totalAmount;
  1501. }
  1502. else {
  1503. $this->Gcheckout->gItemName="ScrapFOTO&trade; Image download";
  1504. $this->Gcheckout->gItemDesc="ScrapFOTO&trade; Image download";
  1505. $this->Gcheckout->gReturnUrl=FULL_BASE_URL.$this->webroot."creativezones/".$rdPage."?tr=".base64_encode($lastTransactionId);
  1506. $this->Gcheckout->gNotifyUrl=FULL_BASE_URL.$this->webroot."creativezones/checkout_notify";
  1507. $this->Gcheckout->customData=$_SESSION['UserId']."^".$sellerId."^".$isAdmin."^".$rdPage."^".$invoice."^".$lastTransactionId."^".$totalAmount;
  1508. }
  1509. $this->Gcheckout->google();
  1510. }
  1511. }
  1512. }
  1513. //checking
  1514. function checkout_notify() {
  1515. /*
  1516. $this->Paypal->paypal_class();
  1517. $this->Paypal->paypal_url = $this->paypalUrl;
  1518. $paypal=0;
  1519. //____________________________________________________IPN DATA SECTION______________________________________________
  1520. //This section is used to catch from PAYPAL IPN data
  1521. if ($this->Paypal->validate_ipn()) {
  1522. $paypal=1;
  1523. if(isset($this->Paypal->ipn_data['payment_gross']) && ($this->Paypal->ipn_data['payment_gross'])!="") {
  1524. $totalPay=$this->Paypal->ipn_data['payment_gross'];
  1525. $custom=explode("^",$this->Paypal->ipn_data['custom']);
  1526. $userId=$custom['0'];
  1527. $sellerId=$custom['1'];
  1528. $isAdmin=$custom['2'];
  1529. $rdPage=$custom['3'];
  1530. $ssnId=$custom['4'];
  1531. $transactionId=$custom['5'];
  1532. $invoice=$this->Paypal->ipn_data['invoice'];
  1533. }
  1534. }
  1535. //This section is used to catch from GOOGLE IPN data
  1536. if(!$paypal) {
  1537. //this section is used to update from google IPN data
  1538. $xml_response = isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:file_get_contents("php://input");
  1539. if($xml_response) {
  1540. $gCustom=$this->parseXmlArray($xml_response);
  1541. $cData=$gCustom['http://checkout.google.com/schema/2']['SHOPPING-CART']['ITEMS']['ITEM']['MERCHANT-PRIVATE-ITEM-DATA'];
  1542. $ipnData=explode("^",$cData);
  1543. $userId=$ipnData['0'];
  1544. $sellerId=$ipnData['1'];
  1545. $isAdmin=$ipnData['2'];
  1546. $rdPage=$ipnData['3'];
  1547. $ssnId=$ipnData['4'];
  1548. $transactionId=$ipnData['5'];
  1549. $invoice=$ipnData['6'];
  1550. $totalPay=$ipnData['7'];
  1551. }
  1552. }
  1553. *
  1554. */
  1555. }
  1556. //checking
  1557. function success() {
  1558. $this->checkSession();
  1559. //
  1560. $paypal=0;
  1561. //____________________________________________________IPN DATA SECTION______________________________________________
  1562. //This section is used to catch from PAYPAL IPN data
  1563. if (isset($_POST['payment_gross']) && ($_POST['payment_gross'])!="") {
  1564. $paypal=1;
  1565. $totalPay=$_POST['payment_gross'];
  1566. $custom=explode("^",$_POST['custom']);
  1567. $userId=$custom['0'];
  1568. $sellerId=$custom['1'];
  1569. $isAdmin=$custom['2'];
  1570. $rdPage=$custom['3'];
  1571. $invoice=$custom['4'];
  1572. $transactionId=$custom['5'];
  1573. }
  1574. //This section is used to catch from GOOGLE IPN data
  1575. if(!$paypal) {
  1576. //this section is used to update from google IPN data
  1577. $xml_response = isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:file_get_contents("php://input");
  1578. if($xml_response) {
  1579. $gCustom=$this->parseXmlArray($xml_response);
  1580. $cData=$gCustom['http://checkout.google.com/schema/2']['SHOPPING-CART']['ITEMS']['ITEM']['MERCHANT-PRIVATE-ITEM-DATA'];
  1581. $ipnData=explode("^",$cData);
  1582. $userId=$ipnData['0'];
  1583. $sellerId=$ipnData['1'];
  1584. $isAdmin=$ipnData['2'];
  1585. $rdPage=$ipnData['3'];
  1586. $invoice=$ipnData['4'];
  1587. $transactionId=$ipnData['5'];
  1588. $totalPay=$ipnData['6'];
  1589. }
  1590. }
  1591. //____________________________________________________XOIMAGE DATABASE UPDATION_____________________________________
  1592. //UPDATE date on TRANSACTION_CREATIVE TABLE
  1593. $queryUpdateTransactionCreative="
  1594. UPDATE transaction_creatives
  1595. SET pay_status='1',invoice='".$invoice."'
  1596. WHERE id='".$transactionId."' AND user_id='".$userId."'";
  1597. mysql_query($queryUpdateTransactionCreative) or die("Error on line : ".__LINE__.mysql_error());
  1598. //UPDATE data to the CREATIVE_CARTS TABLE after successful transaction
  1599. $queryUpdateCreativeCart="
  1600. UPDATE creative_carts
  1601. SET pay_status='1', total_price='".$totalPay."'
  1602. WHERE user_id='".$userId."' AND pay_status='0' AND transaction_creative_id='".$transactionId."' ";
  1603. mysql_query($queryUpdateCreativeCart) or die("Error on line : ".__LINE__.mysql_error());
  1604. //generating the downloadable file
  1605. //Get the list of the downloaded images
  1606. $downloadimg=$this->getCartImages($userId,$transactionId);
  1607. $zipfilename = 'scrapblogimg'.$transactionId.$userId.'.zip';
  1608. //UPDATE transaction_creatives with the scrapfoto filename$zipfilename
  1609. mysql_query("
  1610. UPDATE transaction_creatives
  1611. SET scrapfoto_file='".$zipfilename."'
  1612. WHERE id='".$transactionId."' AND user_id='".$userId."'") or die("Error on line - ".__LINE__.mysql_error());
  1613. ;
  1614. $downloadimgs = array();
  1615. $Imgdestination='';
  1616. foreach($downloadimg as $img) {
  1617. $arr = explode('/', $img);
  1618. $downloadimgs[] = $arr[count($arr)-1];
  1619. $Imgdestination = '../'.substr($img, 0, - strlen($arr[count($arr)-1]));
  1620. }
  1621. $Imgdestination = realpath($Imgdestination).'/';
  1622. $zipdestination = realpath('../app/webroot/creativezone/downloadscraps/').'/';
  1623. $this->Zipfile->addFiles($downloadimgs,$Imgdestination); //array of files
  1624. $this->Zipfile->output($zipfilename,$zipdestination);
  1625. //____________________________________________________TRANSACTION LOG MANAGEMENT_____________________________________
  1626. $userDetails=$this->getUserDetails($userId);
  1627. $queryXouserTransactions=mysql_query("SELECT * FROM xouser_transactions WHERE transaction_head='scrapfoto' AND transaction_title='download' AND invoice_id='".$transactionId."'");
  1628. if(mysql_num_rows($queryXouserTransactions)<=0) {
  1629. $transactionDesc="ScrapFOTO - scraps purchase and download";
  1630. $transactionHead="scrapfoto";
  1631. $transactionTitle="download";
  1632. $invoice=$invoice;
  1633. $invoiceId=$transactionId;
  1634. $statusoffee="nontransactionfee";
  1635. $lastInsetID=$this->transactionMaster($transactionDesc,$transactionHead,$transactionTitle,$invoice,$invoiceId);
  1636. if(!isset($_SESSION['buyTemplate']))
  1637. $this->transactionDetail($userId,$totalPay,'-1',$lastInsetID,1,$statusoffee,0,'finished'); //charged//this code is changed on 7th January 2010(statusfee added as well as paymentstatus value 'finished' added---finished is not in used now.)
  1638. //____________________________________________________MAIL MANAGEMENT________________________________________________
  1639. //this mailing code is here so that it fires just once.
  1640. //check buy template
  1641. if(isset($_SESSION['buyTemplate'])) {
  1642. //update transaction_fee for transaction_creatives
  1643. $tranfee = $this->getConfigAmount('creative commission');
  1644. $tranfee = $tranfee['config_value']/100*$totalPay;
  1645. mysql_query("
  1646. UPDATE transaction_creatives
  1647. SET transaction_fee='".$tranfee."'
  1648. WHERE id='".$transactionId."' AND user_id='".$userId."'") or die("Error on line - ".__LINE__.mysql_error());
  1649. ;
  1650. // “notification of sale” (E7) will be send to User Artist
  1651. $fav = $this->Creative_favorites->findById($_SESSION['buyTemplate']['tmpId']);
  1652. $fav['Creative_favorites']['num_sell']++;
  1653. $this->Creative_favorites->save($fav);
  1654. //save transaction of seller
  1655. $transactionDesc="ScrapFOTO - scraps template purchase and download";
  1656. $this->transactionDetail($userId,$totalPay,'-1',$lastInsetID,$fav['Creative_favorites']['user_id'],$statusoffee,0,'finished1'); //charged//this code is changed on 7th January 2010(statusfee added as well as paymentstatus value 'finished' added---finished is not in used now.)
  1657. //$this->transactionDetail($fav['Creative_favorites']['user_id'],$totalPay,'+1',$lastInsetID,$userId); //paid
  1658. //send mail seller
  1659. $sellDetails=$this->getUserDetails($fav['Creative_favorites']['user_id']);
  1660. if(isset($sellDetails['email'])) {
  1661. $receiver=$fav['Creative_favorites']['user_id'];
  1662. $this->Sendmail->Mail();
  1663. $this->Sendmail->From(FROMMAIL);
  1664. $this->Sendmail->To($sellDetails['email']);
  1665. //$this->Sendmail->Cc($sellDetails['email']);
  1666. //$this->Sendmail->Cc("amarjit@navsoft.in");
  1667. //$this->Sendmail->Bcc( "someoneelse@somewhere.fr");
  1668. $subject="XOimages - Notification of sales";
  1669. $this->Sendmail->Subject($subject);
  1670. $this->set("tranId",$transactionId);
  1671. $this->set("sellerId",$receiver);
  1672. $this->Sendmail->layout='email';
  1673. $this->Sendmail->view= 'mail_notification_sales';
  1674. $this->Sendmail->startup($this);
  1675. $messageBody=$this->Sendmail->bodyText();
  1676. $this->Sendmail->Body($messageBody); // set the body
  1677. $this->Sendmail->Priority(1) ; // set the priority to Low
  1678. $this->Sendmail->Send(); // send the mail
  1679. //mail sent to the user mail account in the system
  1680. $sender=1;
  1681. $this->senderMail($sender,$receiver,$subject,$messageBody);
  1682. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  1683. $this->Sendmail->__destruct();
  1684. //check creative quantity sold
  1685. $quantitysold = $this->getConfigAmount('creative quantity sold');
  1686. if($quantitysold['config_value']==$fav['Creative_favorites']['num_sell']){
  1687. $this->Sendmail->Mail();
  1688. $this->Sendmail->From(FROMMAIL);
  1689. $this->Sendmail->To($sellDetails['email']);
  1690. //$this->Sendmail->Cc($sellDetails['email']);
  1691. //$this->Sendmail->Cc("amarjit@navsoft.in");
  1692. //$this->Sendmail->Bcc( "someoneelse@somewhere.fr");
  1693. $subject="XOimages - Notification of user set price";
  1694. $this->Sendmail->Subject($subject);
  1695. $this->set("tranId",$transactionId);
  1696. $this->set("sellerId",$receiver);
  1697. $this->set('num_sell',$fav['Creative_favorites']['num_sell']);
  1698. $this->Sendmail->layout='email';
  1699. $this->Sendmail->view= 'mail_notification_set_price';
  1700. $this->Sendmail->startup($this);
  1701. $messageBody=$this->Sendmail->bodyText();
  1702. $this->Sendmail->Body($messageBody); // set the body
  1703. $this->Sendmail->Priority(1) ; // set the priority to Low
  1704. $this->Sendmail->Send(); // send the mail
  1705. //mail sent to the user mail account in the system
  1706. $sender=1;
  1707. $this->senderMail($sender,$receiver,$subject,$messageBody);
  1708. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  1709. $this->Sendmail->__destruct();
  1710. //$this->redirect('creativezones/mail_notification_set_price/'.$transactionId.'/'.$receiver);
  1711. }
  1712. }
  1713. }
  1714. //mail sent to the user personal account
  1715. if(isset($userDetails['email'])) {
  1716. $this->Sendmail->Mail();
  1717. $this->Sendmail->From(FROMMAIL);
  1718. $this->Sendmail->To($userDetails['email']);
  1719. //$this->Sendmail->Cc($userDetails['email']);
  1720. //$this->Sendmail->Cc("amarjit@navsoft.in");
  1721. //$this->Sendmail->Bcc( "someoneelse@somewhere.fr");
  1722. $subject="XOimages - Scrapfoto Invoice ".$invoice;
  1723. $this->Sendmail->Subject($subject);
  1724. $this->set("tranId",$transactionId);
  1725. $this->set('amountPaid', $totalPay);
  1726. $this->Sendmail->layout='email';
  1727. $this->Sendmail->view= 'mail_scrapdownload';
  1728. $this->Sendmail->startup($this);
  1729. $messageBody=$this->Sendmail->bodyText();
  1730. $this->Sendmail->Body($messageBody); // set the body
  1731. $this->Sendmail->Priority(1) ; // set the priority to Low
  1732. $this->Sendmail->Attach($zipdestination.$zipfilename, "image/jpeg" ) ; // attach a file of type image/gif
  1733. $this->Sendmail->Send(); // send the mail
  1734. //mail sent to the user mail account in the system
  1735. $sender=1;
  1736. $receiver=$userId;
  1737. $this->senderMail($sender,$receiver,$subject,$messageBody);
  1738. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  1739. $this->Sendmail->__destruct();
  1740. }
  1741. }
  1742. $sql = "SELECT Favorite.id FROM creative_carts as Cart
  1743. LEFT JOIN creative_cart_details CartDetail ON Cart.id = CartDetail.creative_cart_id
  1744. LEFT JOIN creative_favorites Favorite ON Favorite.id = CartDetail.creative_favorite_id
  1745. WHERE Cart.transaction_creative_id='".$transactionId."' ";
  1746. $result = mysql_query($sql);
  1747. if(mysql_num_rows($result)>0) {
  1748. while($row=mysql_fetch_array($result)) {
  1749. mysql_query("UPDATE creative_favorites SET is_temp='0' WHERE id='".$row['id']."' ");
  1750. }
  1751. }
  1752. if(isset($_SESSION['buyTemplate'])) {
  1753. $_SESSION['buyTemplate']['pay'] = 1;
  1754. }
  1755. //
  1756. $this->pageTitle = 'ScrapFOTO&trade; - success';
  1757. $this->layout = 'creativehome';
  1758. $this->creativeType();
  1759. $this->getPublicScrap();
  1760. $this->countFavCart();
  1761. //Initializing all the bradcamp back again so that it all starts all over again
  1762. $this->set("filename","success");//filename should contain the name of the file that should be selected
  1763. $this->set("nextpage","success");
  1764. //_________________________________________________________________________________________________
  1765. $userId=$_SESSION['UserId'];
  1766. $transactionId=base64_decode($this->params['url']['tr']);
  1767. $queryTransactionCreatives=mysql_query("SELECT invoice,scrapfoto_file FROM transaction_creatives WHERE id='".$transactionId."'");
  1768. $fetchTransactionCreatives=mysql_fetch_assoc($queryTransactionCreatives);
  1769. $this->set("transactionInv",$fetchTransactionCreatives['invoice']);
  1770. $this->set('scrapbookfilename',$fetchTransactionCreatives['scrapfoto_file']);
  1771. $downloadimg=$this->getCartImages($_SESSION['UserId'],$transactionId,true);
  1772. $this->set("downloadImage",$downloadimg);
  1773. $this->render('success','creativehome');
  1774. }
  1775. function transactionfee_payment_notify() {
  1776. }
  1777. function transactionfee_success() {
  1778. $this->checkSession();
  1779. //
  1780. $paypal=0;
  1781. //____________________________________________________IPN DATA SECTION______________________________________________
  1782. //This section is used to catch from PAYPAL IPN data
  1783. if (isset($_POST['payment_gross']) && ($_POST['payment_gross'])!="") {
  1784. $paypal=1;
  1785. $totalPay=$_POST['payment_gross'];
  1786. $custom=explode("^",$_POST['custom']);
  1787. $userId=$custom['0'];
  1788. $sellerId=$custom['1'];
  1789. $isAdmin=$custom['2'];
  1790. $rdPage=$custom['3'];
  1791. $invoice=$custom['4'];
  1792. }
  1793. //This section is used to catch from GOOGLE IPN data
  1794. if(!$paypal) {
  1795. //this section is used to update from google IPN data
  1796. $xml_response = isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:file_get_contents("php://input");
  1797. if($xml_response) {
  1798. $gCustom=$this->parseXmlArray($xml_response);
  1799. $cData=$gCustom['http://checkout.google.com/schema/2']['SHOPPING-CART']['ITEMS']['ITEM']['MERCHANT-PRIVATE-ITEM-DATA'];
  1800. $ipnData=explode("^",$cData);
  1801. $userId=$ipnData['0'];
  1802. $sellerId=$ipnData['1'];
  1803. $isAdmin=$ipnData['2'];
  1804. $rdPage=$ipnData['3'];
  1805. $invoice=$ipnData['4'];
  1806. $totalPay=$ipnData['5'];
  1807. }
  1808. }
  1809. //____________________________________________________XOIMAGE DATABASE UPDATION_____________________________________
  1810. $tf = $this->Transaction_creatives->findByInvoice($invoice);
  1811. if($tf) {
  1812. $tf['Transaction_creatives']['is_pay_transaction_fee'] = '1';
  1813. $this->Transaction_creatives->save($tf);
  1814. $sql = "SELECT FX .id
  1815. FROM transaction_creatives TC
  1816. RIGHT JOIN creative_carts C ON ( C.transaction_creative_id = TC.id )
  1817. RIGHT JOIN creative_cart_details CDT ON ( CDT.creative_cart_id = C.id )
  1818. RIGHT JOIN creative_favorites F ON ( F.id = CDT.creative_favorite_id )
  1819. RIGHT JOIN creative_favorites FX ON ( FX.ssn_id = F.ssn_id AND FX.is_republished = '1' )
  1820. WHERE TC.invoice = '".$invoice."'
  1821. LIMIT 1 ";
  1822. $result = mysql_query($sql);
  1823. if(mysql_num_rows($result)>0){
  1824. $row = mysql_fetch_assoc($result);
  1825. $sql = "UPDATE creative_favorites SET is_blocked='0' WHERE id='".$row['id']."'";
  1826. mysql_query($sql);
  1827. }
  1828. $this->set('sql',$sql);
  1829. //check unblock user
  1830. $result = mysql_query("SELECT * FROM creative_favorites WHERE user_id ='".$userId."' and is_blocked='1' LIMIT 1");
  1831. if(mysql_num_rows($result)<=0){
  1832. mysql_query("UPDATE user_payment_setup SET is_blocked='0' WHERE user_id ='".$userId."' ");
  1833. }
  1834. }
  1835. $userDetails=$this->getUserDetails($userId);
  1836. $queryXouserTransactions=mysql_query("SELECT * FROM xouser_transactions WHERE transaction_head='scrapfoto' AND transaction_title='comission paid' AND invoice='".$invoice."'");
  1837. if(mysql_num_rows($queryXouserTransactions)<=0) {
  1838. $transactionDesc="ScrapFOTO - scraps transaction fee";
  1839. $transactionHead="scrapfoto";
  1840. $transactionTitle="comission paid";
  1841. $invoice=$invoice;
  1842. $invoiceId=0;
  1843. $statusoffee="projectfee";
  1844. $lastInsetID=$this->transactionMaster($transactionDesc,$transactionHead,$transactionTitle,$invoice,$invoiceId);
  1845. $this->transactionDetail($userId,$totalPay,'+1',$lastInsetID,1,$statusoffee,0,'finished'); //charged//this code is changed on 7th January 2010(statusfee added as well as paymentstatus value 'finished' added---finished is not in used now.)
  1846. //$this->transactionDetail($userId,$totalPay,'+1',$lastInsertId,1); //paid//this code is blocked on 7th January 2010
  1847. //____________________________________________________MAIL MANAGEMENT________________________________________________
  1848. //this mailing code is here so that it fires just once.
  1849. /*if(isset($userDetails['email'])) {
  1850. $this->Sendmail->Mail();
  1851. $this->Sendmail->From(FROMMAIL);
  1852. $this->Sendmail->To($userDetails['email']);
  1853. //$this->Sendmail->Cc($sellDetails['email']);
  1854. //$this->Sendmail->Cc("amarjit@navsoft.in");
  1855. //$this->Sendmail->Bcc( "someoneelse@somewhere.fr");
  1856. $subject="XOimages Notification of sales";
  1857. $this->Sendmail->Subject($subject);
  1858. $this->set("tranId",$transactionId);
  1859. $this->Sendmail->layout='email';
  1860. $this->Sendmail->view= 'mail_notification_sales';
  1861. $this->Sendmail->startup($this);
  1862. $messageBody=$this->Sendmail->bodyText();
  1863. $this->Sendmail->Body($messageBody); // set the body
  1864. $this->Sendmail->Priority(1) ; // set the priority to Low
  1865. $this->Sendmail->Send(); // send the mail
  1866. //mail sent to the user mail account in the system
  1867. $sender=1;
  1868. $receiver=$userId;
  1869. $this->senderMail($sender,$receiver,$subject,$messageBody);
  1870. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  1871. $this->Sendmail->__destruct();
  1872. }*/
  1873. }
  1874. $this->pageTitle = 'ScrapFOTO&trade; - transaction fee success';
  1875. $this->layout = 'creativemysales';
  1876. $this->creativeType();
  1877. $this->countFavCart();
  1878. $this->getPublicScrap();
  1879. $this->set('transactionInv',$invoice);
  1880. }
  1881. //test
  1882. function mail_scrapdownload($tranId) {
  1883. $this->layout = 'email';
  1884. $this->set("tranId",$tranId);
  1885. }
  1886. function mail_notification_set_price($tranId,$receiver) {
  1887. $this->layout = 'email';
  1888. $this->set('num_sell',2);
  1889. $this->set("tranId",$tranId);
  1890. $this->set("sellerId",$receiver);
  1891. }
  1892. function setpriceproduct($ssn_id){
  1893. $this->checkSession();
  1894. $this->layout = 'creativedetail';
  1895. $this->creativeType();
  1896. $this->countFavCart();
  1897. $this->getRankScrap();
  1898. $this->getFeaturedScrap();
  1899. $this->getPublicScrap();
  1900. $this->set('id',$ssn_id);
  1901. if($ssn_id!=null) {
  1902. $query = "SELECT * FROM creative_favorites WHERE ssn_id='".$ssn_id."' AND user_id='".$_SESSION['UserId']."' and is_republished='1' LIMIT 1 ";
  1903. $favs = mysql_query($query);
  1904. if($favs && mysql_num_rows($favs)>0){
  1905. $fav = mysql_fetch_array($favs);
  1906. $fav = $this->Creative_favorites->findById($fav['id']);
  1907. if($this->data) {
  1908. $fav['Creative_favorites']['price'] = $this->data['creativezones']['price'];
  1909. $this->Creative_favorites->save($fav);
  1910. }
  1911. $this->set('price',$fav['Creative_favorites']['price']);
  1912. }
  1913. }
  1914. }
  1915. function downloadscraps() {
  1916. $fileName=$this->params['url']['f'];
  1917. $basePath='../app/webroot/creativezone/downloadscraps/';
  1918. $this->Download->downloadFile($basePath,$fileName);
  1919. }
  1920. function getUserLastTransaction($userId) {
  1921. $queryTransactionCreatives=mysql_query("SELECT id FROM transaction_creatives WHERE user_id='".$userId."' ORDER BY id DESC") or die("Error on line - ".__LINE__.mysql_error());
  1922. if(mysql_num_rows($queryTransactionCreatives)>0) {
  1923. $fetchTransactionCreatives=mysql_fetch_assoc($queryTransactionCreatives);
  1924. return $fetchTransactionCreatives;
  1925. }
  1926. }
  1927. function psuccess() {
  1928. $this->checkSession();
  1929. $this->pageTitle = 'ScrapFOTO&trade; - success';
  1930. $this->layout = 'creativedetail';
  1931. $this->getPublicScrap();
  1932. //This ct variable comes from INDEX page and CREATIVETEMPLATE page
  1933. $id=0;
  1934. if(isset($this->params['url']['ct']))
  1935. $id=base64_decode($this->params['url']['ct']);
  1936. //This ct variable comes from CREATIVETEMPLATE page
  1937. $tmpImg=0;
  1938. if(isset($this->params['url']['tmp']))
  1939. $tmpImg=base64_decode($this->params['url']['tmp']);
  1940. $this->set("cType",$id);
  1941. $this->set("cTemplate",$tmpImg);
  1942. $this->countFavCart();
  1943. //Initializing all the bradcamp back again so that it all starts all over again
  1944. $this->set("filename","success"); //filename should contain the name of the file that should be selected
  1945. $_SESSION['bradcamp_creative'][100]=$this->params['action']; //we are passing the name of the file to keep track which step is visited
  1946. $this->set("nextpage","success");
  1947. //_________________________________________________________________________________________________
  1948. $transactionId=0;
  1949. if(isset($this->params['url']['tid']))
  1950. $transactionId= base64_decode($this->params['url']['tid']);
  1951. $queryTransactionCreatives=mysql_query("SELECT invoice FROM transaction_creatives WHERE id='".$transactionId."'");
  1952. $fetchTransactionCreatives=mysql_fetch_assoc($queryTransactionCreatives);
  1953. $this->set("transactionInv",$fetchTransactionCreatives['invoice']);
  1954. $zipfilename = 'scrapblogimg'.$transactionId.$_SESSION['UserId'].'.zip';
  1955. $this->set('scrapbookfilename',$zipfilename);
  1956. $downloadimg=$this->getCartImages($_SESSION['UserId'],$transactionId);
  1957. $this->set("downloadImage",$downloadimg);
  1958. }
  1959. function scrapsbuynow() {
  1960. $this->checkSession();
  1961. $this->pageTitle = 'ScrapFOTO&trade; - Payment';
  1962. $this->layout = 'creativedetail';
  1963. $this->getPublicScrap();
  1964. if(isset($this->params['url']['seller'])) {
  1965. $sellerId=base64_decode($this->params['url']['seller']);
  1966. $cartsql = "
  1967. SELECT CM.id,Cfav.id as favid,CM.product_name,Creativedetail.imagename,
  1968. CM.qty,CM.price ,(CM.price*CM.qty) as subtotal
  1969. from creative_carts CM
  1970. LEFT JOIN creative_cart_details Creativedetail ON CM.id =Creativedetail.creative_cart_id
  1971. LEFT JOIN creative_favorites Cfav ON CM.product_name = Cfav.title
  1972. LEFT JOIN creative_template_pages ctemppage ON Cfav.id=ctemppage.id
  1973. where
  1974. CM.user_id='".$_SESSION['UserId']."' AND CM.ssn_id='".session_id()."'and CM.pay_status='0' ";
  1975. $this->set('mycartsql',$cartsql);
  1976. $newcartsql ="
  1977. SELECT ifnull( Buser.username, 'NA') AS username,
  1978. Cfav.id , Cfav.user_id,
  1979. COUNT( Cfav.title) as creative_count
  1980. FROM creative_carts Creativecart
  1981. LEFT JOIN creative_favorites Cfav ON Creativecart.product_name = Cfav.title
  1982. LEFT JOIN users Buser ON ( Cfav.user_id = Buser.id )
  1983. WHERE Creativecart.user_id = '".$_SESSION['UserId']."'
  1984. AND Creativecart.ssn_id = '".session_id()."'
  1985. AND Creativecart.pay_status = '0' AND Cfav.user_id='".$sellerId."'
  1986. GROUP BY Cfav.user_id
  1987. ";
  1988. $this->set('newmycartsql',$newcartsql);
  1989. if($sellerId==$_SESSION['UserId']) {
  1990. $this->set("sellerId",1);
  1991. $paymentMethods=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  1992. }
  1993. else {
  1994. $this->set("sellerId",$sellerId);
  1995. $paymentMethods=$this->getPaymentMethodsUsers($sellerId);
  1996. }
  1997. $this->set("paymentMethods",$paymentMethods);
  1998. }
  1999. }
  2000. //checking
  2001. function countFavCart() {
  2002. //get creativeFavCount
  2003. $creativeFavCount=0;
  2004. if(isset($_SESSION['UserId'])) {
  2005. if(isset($_SESSION['buyTemplate']['idNew'])) {
  2006. $favQry = mysql_query("SELECT * FROM creative_favorites WHERE user_id ='".$_SESSION['UserId']."' AND id='".$_SESSION['buyTemplate']['idNew']."'") or die("Error on line :".__LINE__.mysql_error());
  2007. }else {
  2008. $favQry = mysql_query("SELECT * FROM creative_favorites WHERE user_id ='".$_SESSION['UserId']."' AND is_temp='0' AND is_republished='1' ") or die("Error on line :".__LINE__.mysql_error());
  2009. }
  2010. $creativeFavCount = mysql_num_rows($favQry);
  2011. }
  2012. $this->set("creativeFavCount",$creativeFavCount);
  2013. //get creativeCart Count
  2014. $creativeCart=0;
  2015. if(isset($_SESSION['UserId'])) {
  2016. $creativeCart = @mysql_num_rows(mysql_query("SELECT * FROM creative_carts as CC, creative_cart_details as CD, creative_favorites as CF WHERE CC.user_id=".$_SESSION['UserId']." AND CC.pay_status='0' AND CC.id=CD.creative_cart_id AND CD.creative_favorite_id=CF.id AND CD.creative_favorite_id>0"));
  2017. }
  2018. $this->set("creativeCart",$creativeCart);
  2019. //get config payment
  2020. $result = $this->getConfigAmount('creative price');
  2021. $this->set("creative_price",number_format($result['config_value'],2));
  2022. return $creativeCart;
  2023. }
  2024. //ok
  2025. function getCartDetails() {
  2026. $queryCreativeCarts=mysql_query("
  2027. SELECT CM.id,CM.cart_name,(CD.price*CD.qty) as subTotal,CD.product_name,CD.qty,CD.id as cart_detail_id,CF.fileThumb2 as imagename
  2028. FROM creative_carts CM,creative_cart_details CD, creative_favorites as CF
  2029. WHERE CM.id=CD.creative_cart_id AND CD.creative_favorite_id=CF.id AND CM.pay_status='0' AND CM.user_id='".$_SESSION['UserId']."'
  2030. ") or die("Error on line : ".__LINE__.mysql_error());
  2031. $this->set("queryCreativeCarts",$queryCreativeCarts);
  2032. }
  2033. //ok
  2034. function removefromcart() {
  2035. $cartId =0;
  2036. if(isset($this->params['url']['cartid']) && isset($this->params['url']['cartdtid']) && isset($this->params['url']['act']) && $this->params['url']['act']=='del' ) {
  2037. $cartId=base64_decode($this->params['url']['cartid']);
  2038. $cartdtId=base64_decode($this->params['url']['cartdtid']);
  2039. mysql_query("DELETE FROM creative_cart_details WHERE creative_cart_id='".$cartId."' AND id ='".$cartdtId."'");
  2040. $this->set("action",strtoupper($this->params['url']['act']));
  2041. }
  2042. $this->set("cartId",$cartId);
  2043. if(isset($this->params['url']['act']) && $this->params['url']['act']=='edit') {
  2044. $this->set("action",strtoupper($this->params['url']['act']));
  2045. }
  2046. //this is to check whther the delete method is called from CREATIVE_FAVORITE function or CREATIVE_CART
  2047. if(isset($this->params['url']['f']))
  2048. $this->set("f",$this->params['url']['f']);
  2049. $this->getCartDetails();
  2050. $this->getUserDetails();
  2051. $this->countFavCart();
  2052. $fetchAdminPaymentSetup=$this->getPaymentMethods(1); // that means payment will go to the admin paymenbt id
  2053. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  2054. $this->render("cartlist","ajax");
  2055. }
  2056. //checking
  2057. function delfavorite() {
  2058. $this->checkSession();
  2059. if(isset($this->params['url']['fid'])) {
  2060. $favId=base64_decode($this->params['url']['fid']);
  2061. $sql = "SELECT * FROM creative_favorites WHERE id='".$favId."' AND user_id='".$_SESSION['UserId']."'";
  2062. $result = mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2063. if(mysql_num_rows($result)>0) {
  2064. $sql="UPDATE creative_favorites SET is_temp='1' WHERE id='".$favId."' AND user_id='".$_SESSION['UserId']."'";
  2065. mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2066. /*$sql="DELETE FROM creative_favorites_details WHERE creative_favorite_id='".$favId."'";
  2067. mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2068. $sql="DELETE FROM creative_favorite_comments WHERE creative_favorite_id='".$favId."'";
  2069. mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2070. $sql="DELETE FROM creative_favorite_lovers WHERE creative_favorite_id='".$favId."'";
  2071. mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2072. $sql="DELETE FROM creative_favorite_tags WHERE creative_favorite_id='".$favId."'";
  2073. mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2074. $sql="DELETE FROM creative_favorite_voting WHERE creative_favorite_id='".$favId."'";
  2075. mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2076. */
  2077. //note check delete item in cart
  2078. //get cart not pay
  2079. $sql = "SELECT * FROM creative_carts WHERE pay_status='0'";
  2080. $result = mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2081. while ($row = mysql_fetch_array($result)) {
  2082. $sql="DELETE FROM creative_cart_details WHERE creative_cart_id='".$row['id']."' AND creative_favorite_id='".$favId."'";
  2083. mysql_query($sql) or die("Error on line : ".__LINE__.mysql_error());
  2084. }
  2085. }
  2086. }
  2087. if(isset($_SESSION['buyTemplate']['idNew'])) {
  2088. unset($_SESSION['buyTemplate']);
  2089. $this->redirect("/creativezones/index");
  2090. }else {
  2091. $this->redirect("/creativezones/creative_favorite");
  2092. }
  2093. }
  2094. //checking
  2095. function addtocart() {
  2096. $favId=base64_decode($this->data['xoevent']['favoriteId']);
  2097. $result=mysql_query(" SELECT *
  2098. FROM creative_favorites
  2099. WHERE id='".$favId."' AND user_id='".$_SESSION['UserId']."'");
  2100. if(mysql_num_rows($result)>0) {
  2101. $fav=mysql_fetch_assoc($result);
  2102. $productId=$fav['id'];
  2103. $cart_name="Scrap";
  2104. $price=$fav['price'];
  2105. $productName=$fav['title'];
  2106. if(!isset($_SESSION['buyTemplate']) || !isset($_SESSION['buyTemplate']['tmpId'])){
  2107. $creative_price=$this->getConfigAmount('creative price');
  2108. $price = $creative_price['config_value'];
  2109. }
  2110. $result = mysql_query("SELECT * FROM creative_carts WHERE user_id='".$_SESSION['UserId']."' AND pay_status='0' LIMIT 1");
  2111. if(mysql_num_rows($result)>0) {
  2112. $cart = mysql_fetch_assoc($result);
  2113. $cart_id = $cart['id'];
  2114. }else {
  2115. mysql_query("INSERT INTO
  2116. creative_carts(user_id,cart_name,transaction_creative_id,pay_status)
  2117. VALUES('".$_SESSION['UserId']."','".$cart_name."','0','0')") or die("Error on line : ".__LINE__.mysql_error());
  2118. $cart_id=mysql_insert_id();
  2119. }
  2120. $result = mysql_query("SELECT * FROM creative_cart_details WHERE creative_cart_id='".$cart_id."' AND creative_favorite_id='$productId' LIMIT 1");
  2121. if(mysql_num_rows($result)>0) {
  2122. $cartdetail = mysql_fetch_assoc($result);
  2123. mysql_query("UPDATE FROM creative_cart_details SET product_name='".$productName."' price='$price',qty='1' WHERE id='".$cartdetail['id']."' ");
  2124. }else {
  2125. mysql_query("INSERT INTO creative_cart_details SET creative_cart_id='$cart_id' ,creative_favorite_id='$productId', product_name='".$productName."',price='$price',qty='1'");
  2126. }
  2127. }
  2128. $this->getCartDetails();
  2129. $this->countFavCart();
  2130. $this->render("addtocart","ajax");
  2131. }
  2132. function photolover($id=null) {
  2133. if(isset($_SESSION['UserId'])&& $id) {
  2134. $checklover = "Select * from creative_favorite_lovers where user_id='".$_SESSION['UserId']."' and creative_favorite_id='".$id."'" ;
  2135. $checklover_res = mysql_query($checklover);
  2136. $checklover_res_num = mysql_num_rows($checklover_res);
  2137. if($checklover_res_num==0) {
  2138. $insertlover = "INSERT INTO creative_favorite_lovers SET user_id='".$_SESSION['UserId']."', creative_favorite_id='".$id."' ";
  2139. $insertlover=mysql_query($insertlover);
  2140. }
  2141. }
  2142. $checklover = "Select * from creative_favorite_lovers where creative_favorite_id='".$id."'" ;
  2143. $checklover_res = mysql_query($checklover);
  2144. $checklover_res_num = mysql_num_rows($checklover_res);
  2145. $this->set('nooflover', $checklover_res_num);
  2146. $this->set('photoId', $id);
  2147. $this->render('photolover', 'ajax');
  2148. }
  2149. function addtag($photoId=null) {
  2150. /* */
  2151. $this->set('photoImageId',$_REQUEST['hfphotopid']);
  2152. if(isset($_REQUEST['hfphotopid']) && $_REQUEST['hfphotopid']>0 && isset($_SESSION['UserId']) && addslashes($_REQUEST['phototag'])!='Enter Tag') {
  2153. /* INSERT INTO TAGE TABLE */
  2154. $insersql = "INSERT INTO creative_favorite_tags SET user_id='".$_SESSION['UserId']."',creative_favorite_id='".$_REQUEST['hfphotopid']."',tagname='".addslashes($_REQUEST['phototag'])."' ";
  2155. $insersql_res = mysql_query($insersql);
  2156. }
  2157. $this->set('photoImageId', $_REQUEST['hfphotopid']);
  2158. $this->render('taglist', 'ajax');
  2159. }
  2160. function Postreview() {
  2161. if(isset($_REQUEST['hfphotoid']) && $_REQUEST['hfphotoid']>0 && isset($_SESSION['UserId'])) {
  2162. /* Getting out the review*/
  2163. $selectRec= "Select * from creative_favorite_comments where user_id='".$_SESSION['UserId']."' and creative_favorite_id='".$_REQUEST['hfphotoid']."'" ;
  2164. $selectRec_res = mysql_query($selectRec);
  2165. if(mysql_num_rows($selectRec_res)==0) {
  2166. $insertIntoreview = "Insert into creative_favorite_comments SET user_id='".$_SESSION['UserId']."',creative_favorite_id='".$_REQUEST['hfphotoid']."',comment_desc='".addslashes($_REQUEST['reviewdesc'])."' ";
  2167. mysql_query($insertIntoreview);
  2168. }
  2169. }
  2170. $this->set('photoId', $_REQUEST['hfphotoid']);
  2171. $this->render('reviewlist', 'ajax');
  2172. }
  2173. function getCreativeType($scrapId) {
  2174. $queryCreativeType=mysql_query("SELECT * FROM creative_type WHERE id='".$scrapId."'");
  2175. $fetchCreativeType=mysql_fetch_assoc($queryCreativeType);
  2176. return $fetchCreativeType;
  2177. }
  2178. function myscrapxing($idDelete=null) {
  2179. $this->checksession();
  2180. $this->layout = 'creativeinner';
  2181. ############################### Page Title & Head ############################
  2182. $this->pageTitle = 'My ScrapFOTO - My Favorite';
  2183. $this->set('pagehead','My Favorite');
  2184. if($idDelete!=null) {
  2185. $delquery ="UPDATE creative_favorites SET is_temp='1' where user_id='".$_SESSION['UserId']."' AND id='".base64_decode($idDelete)."' ";
  2186. mysql_query($delquery);
  2187. }
  2188. ############################### Page Title & Head ############################
  2189. /* Pagination and PHOTO listing */
  2190. $select = " Select X.fileThumb2 as template_img,X.price,X.id,X1.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat";
  2191. $from=" FROM creative_favorites X
  2192. RIGHT JOIN creative_favorites X1 ON ( X1.ssn_id = X.ssn_id AND X1.is_republished ='1' )
  2193. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  2194. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  2195. LEFT JOIN users Xuser ON X1.user_id = Xuser.id
  2196. LEFT JOIN user_details Xuserdetail ON X1.user_id = Xuserdetail.user_id
  2197. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  2198. $where=" WHERE X.is_blocked='0' AND X.is_temp='0' ";
  2199. $where.=" AND X.user_id='".$_SESSION['UserId']."' ";
  2200. $others=" group by X.id ";
  2201. $others.=" order by X.id desc";
  2202. $PassParameter='';
  2203. $fltr='';
  2204. $CountField="X.id";
  2205. $this->set("controller","creativezones");
  2206. $this->set("action","myscrapxing");
  2207. $this->set("parameter",$PassParameter);
  2208. $this->set("fltr",$fltr);
  2209. $this->set('sql',$select.$from.$where.$others);
  2210. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  2211. if(isset($this->params['url']['Page']) || (isset($fltr) && $fltr!="") || $idDelete!=null) {
  2212. $this->render("myscrapxing2","ajax");
  2213. }
  2214. /**/
  2215. $this->creativeType();
  2216. $this->countFavCart();
  2217. $this->getPublicScrap();
  2218. //echo $select;echo $from;echo $where;echo $others; echo $CountField;
  2219. }
  2220. function approve() {
  2221. $this->checkSession();
  2222. $this->layout = 'creativeinner';
  2223. $viewSearchType = '';
  2224. if((isset($this->params['url']['hfsearch']) && $this->params['url']['hfsearch']!='') || isset($_REQUEST['hfsearch']) )
  2225. $viewSearchType=$_REQUEST['hfsearch'];
  2226. ############################### Page Title & Head ############################
  2227. $this->pageTitle = 'ScrapFOTO&trade; '.'Approve';
  2228. $this->set('pagehead','Approve');
  2229. ############################### Page Title & Head ############################
  2230. /* Pagination and PHOTO listing */
  2231. $select = " Select X.is_featured,X.fileThumb2 as template_img,X.price,X.viewed,X.ssn_id,X.width,X.height,X.id,X.creation,X.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat
  2232. , X.creation, X.is_stop_sell,Ticket.msg_to_user,X.num_sell,X.is_approved";
  2233. $from=" FROM creative_favorites X
  2234. LEFT JOIN creative_tickets Ticket ON X.id = Ticket.creative_favorites_id
  2235. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  2236. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  2237. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  2238. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  2239. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  2240. $where=" WHERE X.user_id='".$_SESSION['UserId']."' AND X.is_blocked='0' AND X.is_temp='0' AND X.type='0' AND X.is_approved='1' ";
  2241. $searchpass='';
  2242. if($viewSearchType=='title' && isset($_REQUEST['txtsrch']) && $_REQUEST['txtsrch']!='') {
  2243. $where.=" AND X.title like '%".$_REQUEST['txtsrch']."%' ";
  2244. $searchpass = "&txtsrch=".$_REQUEST['txtsrch'] ;
  2245. }
  2246. if($viewSearchType=='prodid') {
  2247. $where.=" AND X.ssn_id like '%".$_REQUEST['txtsrch']."%'";
  2248. $searchpass = "&txtsrch=".$_REQUEST['txtsrch'] ;
  2249. }
  2250. if($viewSearchType=='daterange') {
  2251. if($_REQUEST['inpdatefrom'] && $_REQUEST['inpdatefrom']!='mm/dd/YY') {
  2252. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['inpdatefrom']));
  2253. $urlfromdate = $_REQUEST['inpdatefrom'];
  2254. }
  2255. else {
  2256. $eventFromDate=date("Y-m-d");
  2257. $urlfromdate = $_REQUEST['inpdatefrom'];
  2258. }
  2259. if($_REQUEST['inpdateto'] && $_REQUEST['inpdateto']!='mm/dd/YY') {
  2260. $eventToDate=date("Y-m-d",strtotime($_REQUEST['inpdateto']));
  2261. $urltodate = $_REQUEST['inpdateto'];
  2262. }
  2263. else {
  2264. $eventToDate=date("Y-m-d");
  2265. $urltodate = $_REQUEST['inpdateto'];
  2266. }
  2267. $where.=" AND X.creation between '".$eventFromDate."' and '".$eventToDate."' ";
  2268. $searchpass = "&inpdatefrom=".$urlfromdate."&inpdateto=".$urltodate ;
  2269. }
  2270. $this->set('searchpass',$where);
  2271. $others=" group by X.id ";
  2272. if($viewSearchType=='title')
  2273. $others .=" order by X.title desc ";
  2274. if($viewSearchType=='prodid')
  2275. $others .=" order by X.ssn_id desc ";
  2276. if($viewSearchType=='daterange')
  2277. $others .=" order by X.creation desc ";
  2278. $PassParameter ='';
  2279. if($viewSearchType!='') {
  2280. $PassParameter="hfsearch=".$viewSearchType.$searchpass;
  2281. }
  2282. $CountField="X.id";
  2283. $this->set("controller","creativezones");
  2284. $this->set("action","approve");
  2285. $this->set("parameter",$PassParameter);
  2286. $quantityAllowSell = $this->getConfigAmount('creative quantity sold');
  2287. $this->set('quantityAllowSell',$quantityAllowSell['config_value']);
  2288. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  2289. if(isset($this->params['url']['Page']) || $viewSearchType!='') {
  2290. $this->render("approve_search","ajax");
  2291. }
  2292. /**/
  2293. $this->creativeType();
  2294. $this->countFavCart();
  2295. $this->getPublicScrap();
  2296. }
  2297. function reject() {
  2298. $this->checkSession();
  2299. $this->layout = 'creativeinner';
  2300. $viewSearchType = '';
  2301. if((isset($this->params['url']['hfsearch']) && $this->params['url']['hfsearch']!='') || isset($_REQUEST['hfsearch']) )
  2302. $viewSearchType=$_REQUEST['hfsearch'];
  2303. ############################### Page Title & Head ############################
  2304. $this->pageTitle = 'ScrapFOTO&trade; '.'Reject';
  2305. $this->set('pagehead','Reject');
  2306. ############################### Page Title & Head ############################
  2307. /* Pagination and PHOTO listing */
  2308. $select = " Select X.is_featured,X.fileThumb2 as template_img,X.price,X.viewed,X.ssn_id,X.width,X.height,X.id,X.creation,X.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat
  2309. , X.creation, X.is_stop_sell,Ticket.msg_to_user,X.num_sell,X.is_approved,Ticket.ticket_number";
  2310. $from=" FROM creative_favorites X
  2311. LEFT JOIN creative_tickets Ticket ON X.id = Ticket.creative_favorites_id
  2312. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  2313. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  2314. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  2315. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  2316. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  2317. $where=" WHERE X.user_id='".$_SESSION['UserId']."' AND X.is_blocked='0' AND X.is_temp='0' AND X.type='0' AND X.is_approved='-1' ";
  2318. $searchpass='';
  2319. if($viewSearchType=='title' && isset($_REQUEST['txtsrch']) && $_REQUEST['txtsrch']!='') {
  2320. $where.=" AND X.title like '%".$_REQUEST['txtsrch']."%' ";
  2321. $searchpass = "&txtsrch=".$_REQUEST['txtsrch'] ;
  2322. }
  2323. if($viewSearchType=='prodid') {
  2324. $where.=" AND X.ssn_id like '%".$_REQUEST['txtsrch']."%'";
  2325. $searchpass = "&txtsrch=".$_REQUEST['txtsrch'] ;
  2326. }
  2327. if($viewSearchType=='ticket') {
  2328. $where.=" AND Ticket.ticket_number like '%".$_REQUEST['txtsrch']."%'";
  2329. $searchpass = "&txtsrch=".$_REQUEST['txtsrch'] ;
  2330. }
  2331. if($viewSearchType=='daterange') {
  2332. if($_REQUEST['inpdatefrom'] && $_REQUEST['inpdatefrom']!='mm/dd/YY') {
  2333. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['inpdatefrom']));
  2334. $urlfromdate = $_REQUEST['inpdatefrom'];
  2335. }
  2336. else {
  2337. $eventFromDate=date("Y-m-d");
  2338. $urlfromdate = $_REQUEST['inpdatefrom'];
  2339. }
  2340. if($_REQUEST['inpdateto'] && $_REQUEST['inpdateto']!='mm/dd/YY') {
  2341. $eventToDate=date("Y-m-d",strtotime($_REQUEST['inpdateto']));
  2342. $urltodate = $_REQUEST['inpdateto'];
  2343. }
  2344. else {
  2345. $eventToDate=date("Y-m-d");
  2346. $urltodate = $_REQUEST['inpdateto'];
  2347. }
  2348. $where.=" AND X.creation between '".$eventFromDate."' and '".$eventToDate."' ";
  2349. $searchpass = "&inpdatefrom=".$urlfromdate."&inpdateto=".$urltodate ;
  2350. }
  2351. $this->set('searchpass',$where);
  2352. $others=" group by X.id ";
  2353. if($viewSearchType=='title')
  2354. $others .=" order by X.title desc ";
  2355. if($viewSearchType=='prodid')
  2356. $others .=" order by X.ssn_id desc ";
  2357. if($viewSearchType=='daterange')
  2358. $others .=" order by X.creation desc ";
  2359. if($viewSearchType=='ticket')
  2360. $others .=" order by Ticket.ticket_number desc ";
  2361. $PassParameter ='';
  2362. if($viewSearchType!='') {
  2363. $PassParameter="hfsearch=".$viewSearchType.$searchpass;
  2364. }
  2365. $CountField="X.id";
  2366. $this->set("controller","creativezones");
  2367. $this->set("action","reject");
  2368. $this->set("parameter",$PassParameter);
  2369. $quantityAllowSell = $this->getConfigAmount('creative quantity sold');
  2370. $this->set('quantityAllowSell',$quantityAllowSell['config_value']);
  2371. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  2372. if(isset($this->params['url']['Page']) || $viewSearchType!='') {
  2373. $this->render("approve_search","ajax");
  2374. }
  2375. /**/
  2376. $this->creativeType();
  2377. $this->countFavCart();
  2378. $this->getPublicScrap();
  2379. }
  2380. function submission() {
  2381. $this->checkSession();
  2382. $this->layout = 'creativeinner';
  2383. $viewSearchType = '';
  2384. if((isset($this->params['url']['hfsearch']) && $this->params['url']['hfsearch']!='') || isset($_REQUEST['hfsearch']) )
  2385. $viewSearchType=$_REQUEST['hfsearch'];
  2386. ############################### Page Title & Head ############################
  2387. $this->pageTitle = 'ScrapFOTO&trade; '.'Submisson';
  2388. $this->set('pagehead','Submisson');
  2389. ############################### Page Title & Head ############################
  2390. /* Pagination and PHOTO listing */
  2391. $select = " Select X.is_featured,X.fileThumb2 as template_img,X.price,X.viewed,X.ssn_id,X.width,X.height,X.id,X.creation,X.user_id,X.title,XCreativetype.creative_name ,XCreativetype.id as creativetypeid, X.description,Xuser.username ,COUNT(Xcomment.id) as photoreview , Xuserdetail.user_profile_img , IFNULL(ROUND(AVG(Xrating.vote),0),0) as photorat
  2392. , X.creation, X.is_stop_sell,Ticket.msg_to_user,X.num_sell,X.is_approved,Ticket.ticket_number";
  2393. $from=" FROM creative_favorites X
  2394. LEFT JOIN creative_tickets Ticket ON X.id = Ticket.creative_favorites_id
  2395. LEFT JOIN creative_type XCreativetype ON X.creative_type_id = XCreativetype.id
  2396. LEFT JOIN creative_favorite_comments Xcomment ON X.id = Xcomment.creative_favorite_id
  2397. LEFT JOIN users Xuser ON X.user_id = Xuser.id
  2398. LEFT JOIN user_details Xuserdetail ON X.user_id = Xuserdetail.user_id
  2399. LEFT JOIN creative_favorite_voting Xrating ON X.id = Xrating.creative_favorite_id";
  2400. $where=" WHERE X.user_id='".$_SESSION['UserId']."' AND X.is_blocked='0' AND X.is_temp='0' AND X.type='0' AND X.is_approved='0' ";
  2401. $searchpass='';
  2402. if($viewSearchType=='title' && isset($_REQUEST['txtsrch']) && $_REQUEST['txtsrch']!='') {
  2403. $where.=" AND X.title like '%".$_REQUEST['txtsrch']."%' ";
  2404. $searchpass = "&txtsrch=".$_REQUEST['txtsrch'] ;
  2405. }
  2406. if($viewSearchType=='prodid') {
  2407. $where.=" AND X.ssn_id like '%".$_REQUEST['txtsrch']."%'";
  2408. $searchpass = "&txtsrch=".$_REQUEST['txtsrch'] ;
  2409. }
  2410. if($viewSearchType=='ticket') {
  2411. $where.=" AND Ticket.ticket_number like '%".$_REQUEST['txtsrch']."%'";
  2412. $searchpass = "&txtsrch=".$_REQUEST['txtsrch'] ;
  2413. }
  2414. if($viewSearchType=='daterange') {
  2415. if($_REQUEST['inpdatefrom'] && $_REQUEST['inpdatefrom']!='mm/dd/YY') {
  2416. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['inpdatefrom']));
  2417. $urlfromdate = $_REQUEST['inpdatefrom'];
  2418. }
  2419. else {
  2420. $eventFromDate=date("Y-m-d");
  2421. $urlfromdate = $_REQUEST['inpdatefrom'];
  2422. }
  2423. if($_REQUEST['inpdateto'] && $_REQUEST['inpdateto']!='mm/dd/YY') {
  2424. $eventToDate=date("Y-m-d",strtotime($_REQUEST['inpdateto']));
  2425. $urltodate = $_REQUEST['inpdateto'];
  2426. }
  2427. else {
  2428. $eventToDate=date("Y-m-d");
  2429. $urltodate = $_REQUEST['inpdateto'];
  2430. }
  2431. $where.=" AND X.creation between '".$eventFromDate."' and '".$eventToDate."' ";
  2432. $searchpass = "&inpdatefrom=".$urlfromdate."&inpdateto=".$urltodate ;
  2433. }
  2434. $this->set('searchpass',$where);
  2435. $others=" group by X.id ";
  2436. if($viewSearchType=='title')
  2437. $others .=" order by X.title desc ";
  2438. if($viewSearchType=='prodid')
  2439. $others .=" order by X.ssn_id desc ";
  2440. if($viewSearchType=='daterange')
  2441. $others .=" order by X.creation desc ";
  2442. if($viewSearchType=='ticket')
  2443. $others .=" order by Ticket.ticket_number desc ";
  2444. $PassParameter ='';
  2445. if($viewSearchType!='') {
  2446. $PassParameter="hfsearch=".$viewSearchType.$searchpass;
  2447. }
  2448. $CountField="X.id";
  2449. $this->set("controller","creativezones");
  2450. $this->set("action","submission");
  2451. $this->set("parameter",$PassParameter);
  2452. $quantityAllowSell = $this->getConfigAmount('creative quantity sold');
  2453. $this->set('quantityAllowSell',$quantityAllowSell['config_value']);
  2454. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  2455. if(isset($this->params['url']['Page']) || $viewSearchType!='') {
  2456. $this->render("approve_search","ajax");
  2457. }
  2458. /**/
  2459. $this->creativeType();
  2460. $this->countFavCart();
  2461. $this->getPublicScrap();
  2462. }
  2463. function approve_msg($id,$is_cancel=null) {
  2464. $this->set('id',$id);
  2465. $this->set('is_cancel',$is_cancel);
  2466. if($is_cancel==null) {
  2467. $tt = $this->Creative_tickets->findByCreative_favorites_id($id);
  2468. $this->set('msg',$tt['Creative_tickets']['msg_to_user']);
  2469. }
  2470. }
  2471. function approve_stop_sell($id,$is_stop_sell) {
  2472. $fav = $this->Creative_favorites->findById($id);
  2473. if($fav) {
  2474. $fav['is_stop_sell'] = $is_stop_sell;
  2475. $this->Creative_favorites->save();
  2476. }
  2477. $this->set('id',$id);
  2478. $this->set('is_stop_sell',$is_stop_sell);
  2479. $this->render("approve_stop_sell","ajax");
  2480. }
  2481. function approve_feature($id,$is_cancel=null) {
  2482. $this->set('id',$id);
  2483. $this->set('is_cancel',$is_cancel);
  2484. if($is_cancel==null) {
  2485. $featuredAmount=$this->getConfigAmount('creative featured');
  2486. $this->set('totalAmount',$featuredAmount['config_value']);
  2487. $featuredDay=$this->getConfigAmount('creative featured days');
  2488. $this->set('featuredDay',$featuredDay['config_value']);
  2489. //payment details
  2490. $sellerId = 1;// that means payment will go to the admin paymenbt id
  2491. $fetchAdminPaymentSetup=$this->getPaymentMethods($sellerId);
  2492. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  2493. $this->set("sellerId",$sellerId);
  2494. }
  2495. }
  2496. function approve_set_price($id,$is_cancel=null) {
  2497. $this->set('id',$id);
  2498. $this->set('is_cancel',$is_cancel);
  2499. if($is_cancel==null) {
  2500. if($this->data) {
  2501. $fav = $this->Creative_favorites->findById($id);
  2502. $fav['Creative_favorites']['price'] = $this->data['creativezones']['price'];
  2503. $this->Creative_favorites->save($fav);
  2504. }else {
  2505. $fav = $this->Creative_favorites->findById($id);
  2506. }
  2507. $this->set('price',$fav['Creative_favorites']['price']);
  2508. }
  2509. }
  2510. function mysales() {
  2511. $this->checkSession();
  2512. $this->layout = 'creativemysales';
  2513. $viewSearchType = '';
  2514. if((isset($this->params['url']['hfsearch']) && $this->params['url']['hfsearch']!='') || isset($_REQUEST['hfsearch']) )
  2515. $viewSearchType=$_REQUEST['hfsearch'];
  2516. ############################### Page Title & Head ############################
  2517. $this->pageTitle = 'ScrapFOTO&trade; '.'My Sales';
  2518. $this->set('pagehead','My Sales');
  2519. /* Pagination and PHOTO listing */
  2520. $select = "SELECT X.id, X.ssn_id, X.title, X.creative_type_id, X.width, X.height, X.fileThumb2, X.viewed,X1.user_id AS buyer_id, X1.id AS creative_favorite_buyer, DT.creative_cart_id, TC.total_amount, TC.invoice, TC.trandate,
  2521. TC.transaction_fee,TC.is_pay_transaction_fee
  2522. ";
  2523. $from=" FROM creative_favorites X
  2524. RIGHT JOIN creative_favorites X1 ON ( X.ssn_id = X1.ssn_id AND X1.is_republished = '0')
  2525. RIGHT JOIN creative_cart_details DT ON ( X1.id = DT.creative_favorite_id )
  2526. RIGHT JOIN creative_carts C ON ( C.id = DT.creative_cart_id AND C.pay_status = '1' )
  2527. RIGHT JOIN transaction_creatives TC ON ( C.transaction_creative_id = TC.id AND TC.pay_status='1' )
  2528. ";
  2529. $where=" WHERE X.user_id='".$_SESSION['UserId']."' AND X.is_temp='0' AND X.type='0' AND X.is_republished = '1' ";
  2530. $searchpass='';
  2531. if($viewSearchType=='within' && (isset($_REQUEST['within']) && $_REQUEST['within']!='' ) ) {
  2532. $withinType=$_REQUEST['within'];
  2533. $week=date("Y-m-d G:i:s",mktime(date("G"),date("i"),date("s"),date("m"),(date("d")-7),date("Y")));
  2534. $month=date("Y-m-d G:i:s",mktime(date("G"),date("i"),date("s"),(date("m")-1),date("d"),date("Y")));
  2535. $year=date("Y-m-d G:i:s",mktime(date("G"),date("i"),date("s"),date("m"),date("d"),(date("Y")-1)));
  2536. $date=date("Y-m-d G:i:s");
  2537. if($withinType=="past") {
  2538. $curDate=$date;
  2539. }
  2540. if($withinType=="week") {
  2541. $past=$week;
  2542. $curDate=$date;
  2543. }
  2544. if($withinType=="month") {
  2545. $past=$month;
  2546. $curDate=$date;
  2547. }
  2548. if($withinType=="year") {
  2549. $past=$year;
  2550. $curDate=$date;
  2551. }
  2552. if($withinType=="past")
  2553. $where.=" AND TC.trandate<'".$curDate."'";
  2554. else
  2555. $where.=" AND TC.trandate BETWEEN '".$past."' AND '".$curDate."'";
  2556. $searchpass = "&within=".$withinType ;
  2557. }
  2558. if($viewSearchType=='daterange') {
  2559. if(isset($_REQUEST['sdatefrom']) && $_REQUEST['sdatefrom']!='mm/dd/YY') {
  2560. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['sdatefrom']));
  2561. $urlfromdate = $_REQUEST['sdatefrom'];
  2562. }
  2563. else {
  2564. $eventFromDate=date("Y-m-d");
  2565. $urlfromdate = $_REQUEST['sdatefrom'];
  2566. }
  2567. if(isset($_REQUEST['sdateto']) && $_REQUEST['sdateto']!='mm/dd/YY') {
  2568. $eventToDate=date("Y-m-d",strtotime($_REQUEST['sdateto']));
  2569. $urltodate = $_REQUEST['sdateto'].' 23:59:59';
  2570. }
  2571. else {
  2572. $eventToDate=date("Y-m-d");
  2573. $urltodate = $_REQUEST['sdateto'].' 23:59:59';
  2574. }
  2575. $where.=" AND TC.trandate BETWEEN '".$eventFromDate."' AND '".$eventToDate."' ";
  2576. $searchpass = "&sdatefrom=".$urlfromdate."&sdateto=".$urltodate ;
  2577. }
  2578. if($viewSearchType=='advance') {
  2579. if(isset($_REQUEST['prodid']) && $_REQUEST['prodid']!='') {
  2580. $where.=" AND X.ssn_id like '%".$_REQUEST['prodid']."%' ";
  2581. $searchpass .= "&prodid=".$_REQUEST['prodid'] ;
  2582. }
  2583. if(isset($_REQUEST['invoice']) && $_REQUEST['invoice']!='') {
  2584. $where.=" AND TC.invoice like '%".$_REQUEST['invoice']."%' ";
  2585. $searchpass .= "&invoice=".$_REQUEST['invoice'] ;
  2586. }
  2587. if(isset($_REQUEST['adatefrom']) && $_REQUEST['adatefrom']!='mm/dd/YY') {
  2588. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['adatefrom']));
  2589. $urlfromdate = $_REQUEST['adatefrom'];
  2590. }
  2591. else {
  2592. $eventFromDate=date("Y-m-d");
  2593. $urlfromdate = $_REQUEST['adatefrom'];
  2594. }
  2595. if(isset($_REQUEST['adateto']) && $_REQUEST['adateto']!='mm/dd/YY') {
  2596. $eventToDate=date("Y-m-d",strtotime($_REQUEST['adateto']));
  2597. $urltodate = $_REQUEST['adateto'].' 23:59:59';
  2598. }
  2599. else {
  2600. $eventToDate=date("Y-m-d");
  2601. $urltodate = $_REQUEST['adateto'].' 23:59:59';
  2602. }
  2603. if(isset($_REQUEST['adatefrom']) && isset($_REQUEST['adateto']) && $_REQUEST['adatefrom']!='mm/dd/YY' && $_REQUEST['adateto']!='mm/dd/YY'){
  2604. $where.=" AND TC.trandate BETWEEN '".$eventFromDate."' AND '".$eventToDate."' ";
  2605. $searchpass .= "&adatefrom=".$urlfromdate."&adateto=".$urltodate ;
  2606. }
  2607. }
  2608. $this->set('searchpass',$where);
  2609. //calculator total sell
  2610. $sqltotal= 'SELECT SUM(TC.total_amount) as total_sell '.$from.$where.'';
  2611. $result = mysql_query($sqltotal);
  2612. $row = mysql_fetch_array($result);
  2613. $this->set('total_sell',$row['total_sell']);
  2614. $others=" order by TC.trandate desc ";
  2615. $PassParameter ='';
  2616. if($viewSearchType!='') {
  2617. $PassParameter="hfsearch=".$viewSearchType.$searchpass;
  2618. }
  2619. $CountField="X.id";
  2620. $this->set("controller","creativezones");
  2621. $this->set("action","mysales");
  2622. $this->set("parameter",$PassParameter);
  2623. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  2624. if(isset($this->params['url']['Page']) || $viewSearchType!='') {
  2625. $this->render("mysales_search","ajax");
  2626. }
  2627. /**/
  2628. $this->creativeType();
  2629. $this->countFavCart();
  2630. $this->getPublicScrap();
  2631. }
  2632. function mysales_transaction_fee($invoice,$is_cancel=null) {
  2633. $this->set('id',$invoice);
  2634. $this->set('is_cancel',$is_cancel);
  2635. if($is_cancel==null) {
  2636. $tc = $this->Transaction_creatives->findByInvoice($invoice);
  2637. $this->set('totalAmount',$tc['Transaction_creatives']['transaction_fee']);
  2638. //payment details
  2639. $sellerId = 1;// that means payment will go to the admin paymenbt id
  2640. $fetchAdminPaymentSetup=$this->getPaymentMethods($sellerId);
  2641. $this->set("paymentMethods",$fetchAdminPaymentSetup);
  2642. $this->set("sellerId",$sellerId);
  2643. }
  2644. }
  2645. function mysales_product_detail($invoice,$ssn_id,$is_cancel=null) {
  2646. $this->set('id',$invoice);
  2647. $this->set('is_cancel',$is_cancel);
  2648. $this->set('ssn_id',$ssn_id);
  2649. if($is_cancel==null) {
  2650. $fav = $this->Creative_favorites->findBySsn_id($ssn_id);
  2651. $this->set('fav',$fav['Creative_favorites']);
  2652. }
  2653. }
  2654. function pagination($select,$from,$where,$others,$CountField,$arg,$PassParameter) {
  2655. if(isset($arg['Page']))
  2656. $pageFlag=$arg['Page'];
  2657. $this->set("PassParameter",$PassParameter);
  2658. $SetUserNumberOfVpsPerPage=SHOW_REC; /* Defined in config->paths.php*/
  2659. $this->set("BackgroundClass",'pagination');
  2660. $this->set("SelectedPage",'pagination_over');
  2661. $this->set("Linkpage",'pagination_over');
  2662. $this->set("FirstImage",'fdd.gif');
  2663. $this->set("PreviousImage",'previous.gif');
  2664. $this->set("NextImage",'next.gif');
  2665. $this->set("LastImage",'rewd.gif');
  2666. $UserNumberOfVpsPerPage=4; /* Defined in config->paths.php*/
  2667. if(!is_numeric($UserNumberOfVpsPerPage)|| (intval($UserNumberOfVpsPerPage)!=$UserNumberOfVpsPerPage)||($UserNumberOfVpsPerPage<=0))
  2668. $UserNumberOfVpsPerPage = $SetUserNumberOfVpsPerPage;
  2669. if(!isset($arg['Page'])) $arg['Page']=1;
  2670. if(!isset($arg['Offset'])) $arg['Offset']=0;
  2671. $Query_ForNumber_Records=mysql_query("$select $from $where $others") or die('Line no 120' . mysql_error());
  2672. //$Result_Query_ForNumber_Records=mysql_fetch_object($Query_ForNumber_Records);
  2673. //$NoOfVps=$Result_Query_ForNumber_Records->NoOfVps;
  2674. $NoOfVps=mysql_num_rows($Query_ForNumber_Records);
  2675. $NumberOfVpsPerPage=$UserNumberOfVpsPerPage;
  2676. $NoOfPages=ceil($NoOfVps/$NumberOfVpsPerPage); //3
  2677. if($arg['Offset']==$NoOfVps) {
  2678. if(isset($Offset)) {
  2679. $Offset=$Offset-$NumberOfVpsPerPage;
  2680. $Page--;
  2681. if($Offset<0) {
  2682. $Offset=0;
  2683. $Page=1;
  2684. }
  2685. }else {
  2686. $Offset=0;
  2687. $Page=1;
  2688. }
  2689. }
  2690. $this->set("Page",$arg['Page']);
  2691. $this->set("Offset",$arg['Offset']);
  2692. $this->set("NumberOfVpsPerPage",$NumberOfVpsPerPage);
  2693. $this->set("NoOfPages",$NoOfPages);
  2694. $this->set("UserNumberOfVpsPerPage",$UserNumberOfVpsPerPage);
  2695. //print "$select $from $where $others";
  2696. $this->set("qryOthr","$select $from $where $others");
  2697. $SelectRecord = mysql_query("$select $from $where $others LIMIT ".$arg['Offset'].",$NumberOfVpsPerPage") or die('Line no '.__LINE__ . mysql_error());
  2698. $this->set("query",$SelectRecord);
  2699. }
  2700. function sales() {
  2701. $this->checkSession();
  2702. $this->pageTitle = 'ScrapFOTO&trade; '.'Order History';
  2703. $this->layout = 'creativemysales';
  2704. $this->set('pagehead','Order History');
  2705. $this->creativeType();
  2706. $this->getRankScrap();
  2707. $this->getFeaturedScrap();
  2708. $this->getPublicScrap();
  2709. $this->countFavCart();
  2710. $viewSearchType = '';
  2711. if((isset($this->params['url']['hfsearch']) && $this->params['url']['hfsearch']!='') || isset($_REQUEST['hfsearch']) )
  2712. $viewSearchType=$_REQUEST['hfsearch'];
  2713. $select="SELECT TC. * ,TC.id tranId, C. * , GROUP_CONCAT( DISTINCT CONCAT_WS( '-', C.cart_name) ) AS scrapName";
  2714. $from=" FROM transaction_creatives TC
  2715. LEFT JOIN creative_carts C ON ( C.transaction_creative_id = TC.id )";
  2716. $where=" WHERE TC.user_id = '".$_SESSION['UserId']."' AND TC.pay_status='1' ";
  2717. $searchpass='';
  2718. if($viewSearchType=='within' && (isset($_REQUEST['within']) && $_REQUEST['within']!='' ) ) {
  2719. $withinType=$_REQUEST['within'];
  2720. $week=date("Y-m-d G:i:s",mktime(date("G"),date("i"),date("s"),date("m"),(date("d")-7),date("Y")));
  2721. $month=date("Y-m-d G:i:s",mktime(date("G"),date("i"),date("s"),(date("m")-1),date("d"),date("Y")));
  2722. $year=date("Y-m-d G:i:s",mktime(date("G"),date("i"),date("s"),date("m"),date("d"),(date("Y")-1)));
  2723. $date=date("Y-m-d G:i:s");
  2724. if($withinType=="past") {
  2725. $curDate=$date;
  2726. }
  2727. if($withinType=="week") {
  2728. $past=$week;
  2729. $curDate=$date;
  2730. }
  2731. if($withinType=="month") {
  2732. $past=$month;
  2733. $curDate=$date;
  2734. }
  2735. if($withinType=="year") {
  2736. $past=$year;
  2737. $curDate=$date;
  2738. }
  2739. if($withinType=="past")
  2740. $where.=" AND TC.trandate<'".$curDate."'";
  2741. else
  2742. $where.=" AND TC.trandate BETWEEN '".$past."' AND '".$curDate."'";
  2743. $searchpass = "&within=".$withinType ;
  2744. }
  2745. if($viewSearchType=='daterange') {
  2746. if(isset($_REQUEST['sdatefrom']) && $_REQUEST['sdatefrom']!='mm/dd/YY') {
  2747. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['sdatefrom']));
  2748. $urlfromdate = $_REQUEST['sdatefrom'];
  2749. }
  2750. else {
  2751. $eventFromDate=date("Y-m-d");
  2752. $urlfromdate = $_REQUEST['sdatefrom'];
  2753. }
  2754. if(isset($_REQUEST['sdateto']) && $_REQUEST['sdateto']!='mm/dd/YY') {
  2755. $eventToDate=date("Y-m-d",strtotime($_REQUEST['sdateto']));
  2756. $urltodate = $_REQUEST['sdateto'].' 23:59:59';
  2757. }
  2758. else {
  2759. $eventToDate=date("Y-m-d");
  2760. $urltodate = $_REQUEST['sdateto'].' 23:59:59';
  2761. }
  2762. $where.=" AND TC.trandate BETWEEN '".$eventFromDate."' AND '".$eventToDate."' ";
  2763. $searchpass = "&sdatefrom=".$urlfromdate."&sdateto=".$urltodate ;
  2764. }
  2765. if($viewSearchType=='advance') {
  2766. if(isset($_REQUEST['cartname']) && $_REQUEST['cartname']!='') {
  2767. $where.=" AND C.cart_name like '%".$_REQUEST['cartname']."%' ";
  2768. $searchpass .= "&cartname=".$_REQUEST['cartname'] ;
  2769. }
  2770. if(isset($_REQUEST['invoice']) && $_REQUEST['invoice']!='') {
  2771. $where.=" AND TC.invoice like '%".$_REQUEST['invoice']."%' ";
  2772. $searchpass .= "&invoice=".$_REQUEST['invoice'] ;
  2773. }
  2774. if(isset($_REQUEST['adatefrom']) && $_REQUEST['adatefrom']!='mm/dd/YY') {
  2775. $eventFromDate=date("Y-m-d",strtotime($_REQUEST['adatefrom']));
  2776. $urlfromdate = $_REQUEST['adatefrom'];
  2777. }
  2778. else {
  2779. $eventFromDate=date("Y-m-d");
  2780. $urlfromdate = $_REQUEST['adatefrom'];
  2781. }
  2782. if(isset($_REQUEST['adateto']) && $_REQUEST['adateto']!='mm/dd/YY') {
  2783. $eventToDate=date("Y-m-d",strtotime($_REQUEST['adateto']));
  2784. $urltodate = $_REQUEST['adateto'].' 23:59:59';
  2785. }
  2786. else {
  2787. $eventToDate=date("Y-m-d");
  2788. $urltodate = $_REQUEST['adateto'].' 23:59:59';
  2789. }
  2790. if(isset($_REQUEST['adatefrom']) && isset($_REQUEST['adateto']) && $_REQUEST['adatefrom']!='mm/dd/YY' && $_REQUEST['adateto']!='mm/dd/YY'){
  2791. $where.=" AND TC.trandate BETWEEN '".$eventFromDate."' AND '".$eventToDate."' ";
  2792. $searchpass .= "&adatefrom=".$urlfromdate."&adateto=".$urltodate ;
  2793. }
  2794. }
  2795. $this->set('searchpass',$where);
  2796. //calculator total sell
  2797. $sqltotal= 'SELECT SUM(TC.total_amount) as total_sell '.$from.$where.'';
  2798. $result = mysql_query($sqltotal);
  2799. $row = mysql_fetch_array($result);
  2800. $this->set('total_sell',$row['total_sell']);
  2801. $others=" GROUP BY TC.id ORDER BY TC.id DESC";
  2802. $PassParameter ='';
  2803. if($viewSearchType!='') {
  2804. $PassParameter="hfsearch=".$viewSearchType.$searchpass;
  2805. }
  2806. $CountField="tranId";
  2807. $this->set("controller","creativezones");
  2808. $this->set("action","sales");
  2809. $this->pagination($select,$from,$where,$others,$CountField,$this->params['url'],$PassParameter);
  2810. if(isset($this->params['url']['Page']) || $viewSearchType!='') {
  2811. $this->render("sales2","ajax");
  2812. }
  2813. }
  2814. function getTransactionDetails($transactionId=null) /// Invoice detail
  2815. {
  2816. ##################################################### INVOICE DETAILAS ######################
  2817. $ticketqry = "
  2818. SELECT tranTic.id, tranTic.invoice , tranTic.total_amount , DATE(tranTic.cudate) as saledate , CONCAT(BUYusrdetail.first_name ,' ',BUYusrdetail.last_name) as Buyername ,
  2819. BUYusrdetail.address as Buyeraddress ,IFNULL(BUYCITYName.city_name,'--') as Buyercity , IFNULL(BUYstate.Name,'--') as Buyerstatename , BUYcountry.country_name as BUYercountryname , BUYusrdetail.zip as Buyerzip ,
  2820. POSTBYusrdetail.comp_name as PostCompanyname , CONCAT(POSTBYusrdetail.first_name ,' ',POSTBYusrdetail.last_name) as Postname ,POSTBYusrdetail.email as Postemail,IF(POSTBYusrdetail.land_phone <>'',POSTBYusrdetail.land_phone,'--') as Postphonenumber,
  2821. POSTBYusrdetail.address as Postaddress ,IFNULL(POSTCITYMaster.city_name,'--') as Postcity , IFNULL(POSTstate.Name,'--') as Poststatename , POSTcountry.country_name as Postcountryname , POSTBYusrdetail.zip as Postzip ,
  2822. Tic.plan_name as Eventname , tranTic.total_amount as Totalamount , MEMPLAN.picture as logoimage , SUM(MEMPLANCART.plan_price*MEMPLANCART.quantity) as TicketTotal
  2823. FROM transaction_memberships tranTic
  2824. LEFT JOIN membership_plantype_cart MEMPLANCART ON MEMPLANCART.transaction_membership_id = tranTic.id
  2825. LEFT JOIN membership_plantype MEMPLAN ON (MEMPLANCART.plantype_id = MEMPLAN.plantype_id AND MEMPLANCART.membership_id = MEMPLAN.membership_id)
  2826. LEFT JOIN user_details BUYusrdetail ON MEMPLANCART.user_id = BUYusrdetail.user_id
  2827. LEFT JOIN state BUYstate ON BUYstate.id = BUYusrdetail.state
  2828. LEFT JOIN city_master BUYCITYName ON BUYCITYName.city_id = BUYusrdetail.city
  2829. LEFT JOIN countries BUYcountry ON BUYcountry.id=BUYusrdetail.c_id
  2830. LEFT JOIN memberships Tic On MEMPLANCART.membership_id=Tic.id
  2831. LEFT JOIN user_details POSTBYusrdetail ON tranTic.org_id = POSTBYusrdetail.user_id
  2832. LEFT JOIN state POSTstate ON POSTstate.id = POSTBYusrdetail.state
  2833. LEFT JOIN city_master POSTCITYMaster ON POSTCITYMaster.city_id = POSTBYusrdetail.city
  2834. LEFT JOIN countries POSTcountry ON POSTcountry.id=POSTBYusrdetail.c_id
  2835. WHERE tranTic.id='".$tranId."' and MEMPLANCART.pay_status='1' AND MEMPLANCART.user_id='".$_SESSION['UserId']."'
  2836. AND MEMPLANCART.ssn_id='".session_id()."'
  2837. GROUP BY MEMPLANCART.transaction_membership_id
  2838. ORDER BY MEMPLANCART.id ASC
  2839. ";
  2840. //echo $ticketqry ;
  2841. $qry=mysql_query($ticketqry) or die("Error on line :".__LINE__.mysql_error());
  2842. $this->set("q1",$qry);
  2843. ##################################################### INVOICE DETAILAS ######################
  2844. }
  2845. function creative_invoice_detail(){
  2846. $this->layout = "blank";
  2847. $this->set("tranId",base64_decode($this->params['url']['inv']));
  2848. }
  2849. function printscrap(){
  2850. $this->layout = "blank";
  2851. }
  2852. function sendinvoice() {
  2853. $this->set("urlVars",$this->params['url']);
  2854. $userDetails=$this->getUserDetails($_SESSION['UserId']);
  2855. //____________________________________________________MAIL MANAGEMENT________________________________________________
  2856. //this mailing code is here so that it fires just once.
  2857. //mail sent to the user personal account
  2858. $this->Sendmail->Mail();
  2859. $this->Sendmail->From(FROMMAIL);
  2860. if(isset($userDetails['email'])){
  2861. $this->Sendmail->To($userDetails['email']);
  2862. //$this->Sendmail->Cc("sujoy@navsoft.in");
  2863. //$this->Sendmail->Cc("amarjit@navsoft.in");
  2864. //$this->Sendmail->Bcc( "someoneelse@somewhere.fr");
  2865. $subject="XOimages - Scrapfoto invoice request";
  2866. $this->Sendmail->Subject($subject);
  2867. $this->set("tranId",base64_decode($this->params['url']['inv']));
  2868. $this->Sendmail->layout='email';
  2869. $this->Sendmail->view='mail_invoicerequest';
  2870. $this->Sendmail->startup($this);
  2871. $messageBody=$this->Sendmail->bodyText();
  2872. $this->Sendmail->Body($messageBody); // set the body
  2873. $this->Sendmail->Priority(1) ; // set the priority to Low
  2874. $this->Sendmail->Send(); // send the mail
  2875. //mail sent to the user mail account in the system
  2876. $sender=1;
  2877. $receiver=$_SESSION['UserId'];
  2878. $this->senderMail($sender,$receiver,$subject,$messageBody);
  2879. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  2880. }
  2881. $this->render("invoicesent","ajax");
  2882. }
  2883. function createTransactionNumber($pre) {
  2884. global $db;
  2885. $id = $pre;
  2886. $id .= $this->genRandomStringNumbers(10);
  2887. // check id if exist in db, if not, add
  2888. if($pre=='SPTT') {
  2889. $query ="SELECT id FROM creative_tickets WHERE ticket_number ='".$id."' LIMIT 1";
  2890. }else {
  2891. $query ="SELECT id FROM xouser_transactions WHERE invoice ='".$id."' LIMIT 1";
  2892. }
  2893. $result = mysql_query($query);
  2894. if(mysql_numrows($result) < 1) {
  2895. return $id;
  2896. } else {
  2897. return $this->createTransactionNumber($pre);
  2898. }
  2899. return $this->createTransactionNumber($pre);
  2900. }
  2901. function genRandomStringNumbers($length) {
  2902. $characters = 'ABCEFGHIJKLMNOPQRTUVWXYZ1234567890';
  2903. $string = '';
  2904. for ($c = 0; $c < $length; $c++) {
  2905. $string .= substr($characters, mt_rand(0, strlen($characters)-1), 1);
  2906. }
  2907. return $string;
  2908. }
  2909. function run_cron_job(){
  2910. if (!defined('CRON_DISPATCHER')) {
  2911. exit();
  2912. }else{
  2913. //check Feature
  2914. $query = "UPDATE creative_favorites SET is_featured='0' WHERE is_featured='1' AND featured_time<'".date('Y-m-d G:i:s')."'";
  2915. mysql_query($query);
  2916. //check transaction fee
  2917. $day1 = $this->getConfigAmount('creative settlement time1');
  2918. $day1 = $day1['config_value'];
  2919. $day2 = $this->getConfigAmount('creative settlement time2');
  2920. $day2 = $day2['config_value'];
  2921. if($day1>$day2){
  2922. $tmp = $day1;
  2923. $day1 = $day2;
  2924. $day2 = $tmp;
  2925. }
  2926. $cur_day = date('Y-m-d G:i:s');
  2927. $today = getdate();
  2928. $day_c = $today['mday'];
  2929. $emailtime = $this->getConfigAmount('creative reactivation time');
  2930. $emailtime = $emailtime['config_value'];
  2931. $numday_month = date('t')+0;
  2932. $is_send_mail = ($today['mday']%((int)$numday_month/$emailtime)) == 0 ;
  2933. $this->set('is_send_mail',$is_send_mail);
  2934. $time1 = $today['year'].'-'.$today['mon'].'-'.$day1.' '.$today['hours'].':'.$today['minutes'].':'.$today['seconds'];
  2935. $time2 = $today['year'].'-'.$today['mon'].'-'.$day2.' '.$today['hours'].':'.$today['minutes'].':'.$today['seconds'];
  2936. $compare_date = ($day_c<$day2) ? $time1 : $time2;
  2937. $sql = "SELECT TC.*,FX.ssn_id, FX.is_blocked FROM transaction_creatives TC
  2938. LEFT JOIN creative_carts C ON (C.transaction_creative_id = TC.id)
  2939. LEFT JOIN creative_cart_details CDT ON (CDT.creative_cart_id = C.id)
  2940. LEFT JOIN creative_favorites F ON (F.id = CDT.creative_favorite_id)
  2941. RIGHT JOIN creative_favorites FX ON (F.ssn_id = FX.ssn_id and FX.is_republished='1')
  2942. WHERE TC.transaction_fee>0 AND TC.is_pay_transaction_fee='0'";
  2943. $result = mysql_query($sql);
  2944. $arr = array();
  2945. while($row=mysql_fetch_assoc($result)){
  2946. $trandate = $row['trandate'];
  2947. $tmpdate = new DateTime($trandate);
  2948. if($tmpdate->format('d')>$day2){
  2949. $tmpdate->modify('+1 month');
  2950. $pay_date = $tmpdate->format('Y').'-'.$tmpdate->format('m').'-'.$day1.' '.$tmpdate->format('G').':'.$tmpdate->format('i').':'.$tmpdate->format('s');
  2951. }else{
  2952. $pay_date = $tmpdate->format('Y').'-'.$tmpdate->format('m').'-'.$day2.' '.$tmpdate->format('G').':'.$tmpdate->format('i').':'.$tmpdate->format('s');
  2953. }
  2954. $due_day = (strtotime($trandate)<strtotime($compare_date)) ? (int)((strtotime($cur_day)-strtotime($pay_date))/(24*60*60)) : 0;
  2955. if($due_day>0){
  2956. if(isset($arr[$row['seller_id']]))
  2957. $arr[$row['seller_id']]['due_amount'] += $row['transaction_fee'];
  2958. else{
  2959. $arr[$row['seller_id']]['due_amount'] = $row['transaction_fee'];
  2960. $arr[$row['seller_id']]['due_day'] = $due_day;
  2961. $arr[$row['seller_id']]['ids'] = array();
  2962. }
  2963. $arr[$row['seller_id']]['ids'][$row['ssn_id']]=$row['ssn_id'];
  2964. if($due_day>$arr[$row['seller_id']]['due_day'])
  2965. $arr[$row['seller_id']]['due_day'] = $due_day;
  2966. }
  2967. }
  2968. $blockId = array();
  2969. foreach($arr as $key=>$value){
  2970. $blockId = array_merge($blockId, $value['ids']);
  2971. //check sendmail
  2972. if($is_send_mail)
  2973. $this->mail_reactivation($key,$value['due_amount'],$value['due_day']);
  2974. $sql = "UPDATE user_payment_setup SET is_blocked='1' WHERE user_id='$key' ";
  2975. mysql_query($sql);
  2976. }
  2977. if(count($blockId)>0){
  2978. $sql = "UPDATE creative_favorites SET is_blocked='1' WHERE ssn_id IN ('".join("', '", $blockId)."') AND is_republished='1' ";
  2979. mysql_query($sql);
  2980. }
  2981. }
  2982. }
  2983. function mail_reactivation($user_id,$due_amount,$due_day){
  2984. $userDetails=$this->getUserDetails($user_id);
  2985. //____________________________________________________MAIL MANAGEMENT________________________________________________
  2986. //this mailing code is here so that it fires just once.
  2987. //mail sent to the user personal account
  2988. if(isset($userDetails['email'])){
  2989. $this->Sendmail->Mail();
  2990. $this->Sendmail->From(FROMMAIL);
  2991. $this->Sendmail->To($userDetails['email']);
  2992. $subject="XOimages Reactivation Notification";
  2993. $this->Sendmail->Subject($subject);
  2994. $this->set('user_id',$user_id);
  2995. $this->set('due_amount',$due_amount);
  2996. $this->set('due_day',$due_day);
  2997. $this->Sendmail->layout='email';
  2998. $this->Sendmail->view='mail_reactivation';
  2999. $this->Sendmail->startup($this);
  3000. $messageBody=$this->Sendmail->bodyText();
  3001. $this->Sendmail->Body($messageBody); // set the body
  3002. $this->Sendmail->Priority(1) ; // set the priority to Low
  3003. $this->Sendmail->Send(); // send the mail
  3004. //mail sent to the user mail account in the system
  3005. $sender=1;
  3006. $receiver=$user_id;
  3007. $this->senderMail($sender,$receiver,$subject,$messageBody);
  3008. $this->receiverMail($receiver,$sender,$subject,$messageBody);
  3009. $this->Sendmail->__destruct();
  3010. }
  3011. }
  3012. }
  3013. ?>