PageRenderTime 37ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/app/controllers/creativezones_controller.php

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