$val) $row[$col]=$val; return $row; } function vault_isrestored($row) { //d(vault_isrestored_row,$row); if(!$row) return 0; elseif(isset($row[statuscode])) return $row[statuscode] == VAULTSTATUSCODE_RESTORED; elseif(is_numeric($row)) { return vault_isrestored(vault_getdetail($row)); } elseif(isset($row[propertyid])) { return vault_isrestored(vault_getdetail($row[propertyid])); } elseif(isset($row[clientcompanypropertyid])) { return vault_isrestored(vault_getdetail($row[clientcompanypropertyid])); } else ddie("Invalid call to vault_isvaulted",$row); } function vault_isvaulted($row) { if(!$row) { //d(vault_isvaulted_return_empty); return 0; } elseif(isset($row[statuscode])) { return $row[statuscode] != VAULTSTATUSCODE_NOTYETVAULTED; } elseif(is_numeric($row)) { return vault_isvaulted(vault_getdetail($row)); } elseif(isset($row[clientcompanypropertyid])) { return vault_isvaulted(vault_getdetail($row[clientcompanypropertyid])); } elseif(isset($row[propertyid])) { return vault_isvaulted(vault_getdetail($row[propertyid])); } else ddie("Invalid call to vault_isvaulted",$row); } function vaultstatus($row) // this function takes an archive row and returns an array of statuses { $arr = vaultstatusarr($row) ; return $arr[status]; } function vaultstatusarr($row) // this function takes an archive row and returns an array of statuses { $out=array(); $out[statuscode] = VAULTSTATUSCODE_VAULTED; if($row[archiverestorecompleteddate]) { $out[shortstatus]="Restored"; $out[status]="Restored (".dt_format($row[archiverestorecompleteddate]).")"; $out[statusdate]=dt_format($row[archiverestorecompleteddate]); $out[nextaction]="Re - Vaulted"; $out[nextactiondate]=dt_format( $row[restoreexpiredate]); $out[statuscode] = VAULTSTATUSCODE_RESTORED; $out[propertywriteable] = VAULTPROPERTYWRITEABLE_UNLOCKED; } elseif ($row[archiverestorerequesteddate] && !$row[archiverestorecompleteddate]) { $out[shortstatus]="To be Restored"; $out[status]="To be Restored"; $out[statusdate]=""; $out[nextaction]="Restored"; $out[nextactiondate]=" "; $out[statuscode] = VAULTSTATUSCODE_TOBERESTORED; $out[propertywriteable] = VAULTPROPERTYWRITEABLE_LOCKED; } elseif($row[daysleft]<0) { $out[shortstatus]="Expired"; $out[status]="Expired (".dt_format($row[archivestorethru]).")"; $out[statusdate]=dt_format($row[archivestorethru]); $out[nextaction]="Deletion"; $out[nextactiondate]=dt_format(time()); $out[statuscode] = VAULTSTATUSCODE_EXPIRED; $out[propertywriteable] = VAULTPROPERTYWRITEABLE_LOCKED; } elseif ($row[archivebuildcompleteddate]) { $out[shortstatus]="Archived"; $out[status]="Archived (".dt_format($row[archivebuildcompleteddate]).")"; $out[statusdate]=dt_format($row[archivebuildcompleteddate]); $out[nextaction]="Expiration"; $out[nextactiondate]=dt_format($row[archivestorethru]); $out[propertywriteable] = VAULTPROPERTYWRITEABLE_LOCKED; } elseif ($row[archivebuildrequesteddate]&&!$row[archivebuildcompleteddate]) { if($row[shorttermvault]) $out[shortstatus]="To Be Archived for Export from RIO"; else $out[shortstatus]="To Be Archived"; $out[status]="To Be Archived"; $out[statusdate]=dt_format($row[archivebuildrequesteddate]); $out[nextaction]="Archived"; $out[nextactiondate]= ""; $out[statuscode] = VAULTSTATUSCODE_TOBEARCHIVED; $out[propertywriteable] = VAULTPROPERTYWRITEABLE_LOCKED; } elseif (!$row[archivebuildcompleteddate]) { $out[statuscode] = VAULTSTATUSCODE_NOTYETVAULTED; $out[propertywriteable] = VAULTPROPERTYWRITEABLE_UNLOCKED; } //d(out_vault_row,$out); return $out; } function vault_message($msg,$href="",$title="") { $out = "
"; if($href&&has_access(vaultview)) $out.="$msg"; else $out.=$msg; $out.="
"; return $out; } function vault_property_close($propertyarr,$store_interval, $close_notes, $send_note_to_vendortasks,$amountpaid=0,$receipt="") { //d(is_vaulted, vault_isvaulted($propertyarr)); //ddie("functions_vault.php ".__LINE__,$close_notes); if(!vault_isvaulted($propertyarr)) { //d("functions_vault.php ".__LINE__,$amountpaid); $vaultclientcompanyproperty=FALSE; if(!$propertyarr[propertyid]) $vaultclientcompanyproperty=TRUE; if ($vaultclientcompanyproperty) $propertyid = $propertyarr[clientcompanypropertyid]; else $propertyid = $propertyarr[propertyid]; if ($vaultclientcompanyproperty) $activetasks = get_clienttasks(1,array("clientcompanypropertyid"=>$propertyid)); else $activetasks = get_tasks(1,$propertyid); //$activetasks = get_tasks(1,$propertyid ); if ($vaultclientcompanyproperty) { d("functions_vault.php ".__LINE__,$vaultclientcompanyproperty); $assigns = clientcompanypropertyassignment_get($propertyid,'','',1); if($assigns) { //d(allssignments,$assigns); foreach($assigns as $assign) { if(strstr($assign[clientcompanypropertyassignmentstatus] ,"Pending")) { $sqlup = "update tblclientcompanypropertyassignment set clientcompanypropertyassignmentcompleteddate = now() where clientcompanypropertyassignmentid = $assign[clientcompanypropertyassignmentid]"; d($sqlup); db_exec($sqlup); } elseif($assign[clientcompanypropertyassignmentstatus] == "Accepted") clientcompanypropertyassignment_complete($assign[clientcompanypropertyassignmentid]); } } foreach($activetasks as $k=>$task) { //d(activetasks,$activetasks); $staffemails= ""; $sql=""; if(!$task[clienttaskcompleteddate]) { $sql .= "update tblclienttask set clienttaskcompleteddate = now() where clienttaskid = $task[clienttaskid];"; $staffemails=get_task_emailaddresses($task[clienttaskid]); } if($staffemails) { $arr[note_from_archive_process] = $_POST[closenotes_early]; d(notification_to_assignees,$task[clienttaskid]); d(staffemails,$staffemails); send_trigger_email($propertyid,clientcompanyproperty,propertyarchivednotice,"",$staffemails,0,$arr); } if($sql) { d(close_tasks,$sql); db_exec($sql,1,"",1); } } } else { foreach($activetasks as $k=>$task) { $vendoremail= ""; $staffemails= ""; $sql=""; if( $send_note_to_vendortasks && $task[taskvendorassigneddate] && ! $task[taskvendorcompleteddate]) { $vendoremail = $task[vendoremail]; $sql .= "update tbltask set taskvendorcompleteddate = now() where taskid = $task[taskid];"; } if($task[taskstaffassigneddate] && !$task[taskstaffcompleteddate]) { $sql .= "update tbltask set taskstaffcompleteddate = now() where taskid = $task[taskid];"; $staffemails=get_task_emailaddresses($task[taskid]); } if($staffemails ||$vendoremail) { $arr[note_from_archive_process] = $_POST[closenotes_early]; d(notification_to_assignees,$task[taskid]); d(staffemails,$staffemails); d(vendoremail,$vendoremail); $to="$vendoremail$staffemails"; if($vendoremail&&$staffemails) $to="$vendoremail,$staffemails"; send_trigger_email($propertyid,property,propertyarchivednotice,"",$to,0,$arr); } if($sql) { d(close_tasks,$sql); db_exec($sql,1,"",1); } } } // start here $isclientcompany = ""; if ($vaultclientcompanyproperty) $isclientcompany = "clientcompany"; if($amountpaid) create_note($propertyid,$isclientcompany.property,"Property Marked - To Be Archived in RIO Vault for $storeinterval\n$_POST[closenotes_early]","","",0); else create_note($propertyid,$isclientcompany.property,"Property Marked - To Be Archived for export from RIO \n$_POST[closenotes_early]","","",0); $sql = "update tblpropertyextensionentry set propertyextensionentryvalue = 'Closed' where propertyid = $propertyid and propertyextensionkey = 'propertyextensionstatus'"; d(close_sql, $sql); db_exec($sql); $sql = "select nextval('tblarchive_archiveid_seq') as archiveid"; $next = db_first($sql); $maxid[] = $next[archiveid]; if(is_array($maxid)) $maxid = implode(",",$maxid); if ($vaultclientcompanyproperty) { $sql = "insert into tblarchive (companyid, propertyid, clientcompanyid, clientcompanypropertyid, archivecreatedby, archivebuildrequesteddate, archivebuildrequestedby, archivestoreinterval, archivestorethru, archiveamountpaid,archivereceipt) select 0 as companyid, 0 as propertyid, clientcompanyid, clientcompanypropertyid, ".loginid().", now(), ".loginid().", '$store_interval' , now()::date + interval '$store_interval', 0$amountpaid, '".db_col($receipt)."' from tblclientcompanyproperty where clientcompanypropertyid = $propertyid and clientcompanypropertyid not in (select clientcompanypropertyid from tblarchive) "; } else { $sql = "insert into tblarchive (companyid, propertyid, archivecreatedby, archivebuildrequesteddate, archivebuildrequestedby, archivestoreinterval, archivestorethru, archiveamountpaid,archivereceipt) select companyid, propertyid, ".loginid().", now(), ".loginid().", '$store_interval' , now()::date + interval '$store_interval', 0$amountpaid, '".db_col($receipt)."' from tblproperty where propertyid = $propertyid and propertyid not in (select propertyid from tblarchive) "; } d(insert_sql, $sql); db_exec($sql); $sql = "insert into tblarchivenote (archiveid,archivenotecreatedby,archivenotecreateddate,archivenotesubject,archivenotetext) values ($maxid , ".loginid()." , now() , 'Closed Note' , '".db_col($close_notes)."')"; db_exec($sql,1); } } function vault_getproperties($propertyid=0,$limit=500, $type="",$companyid=0, $extrasql="") //$type==(expired, or ..) { if( !is_numeric($propertyid)) $propertyid=0; //Hotfix - The code below needs to be removed after QA finishes testing on joetest. This is a part of task 22162 - Unable to vault. 11/03/2015 //if(loginid()==35945 || loginid()==49622 || loginid()==49625) // $vaultisextendableinterval = "10 YEARS"; //else $vaultisextendableinterval = VAULTISEXTENDABLEINTERVAL;//Hotfix - The value here can be put in for the variable in the sql below, and this line deleted. $sql = "select tblarchive.* , coalesce(companyname, clientcompanyname) as companyname , archivephotokb + archivedocumentkb as totalsize ,case when archiverestorecompleteddate is not null then archiverestorecompleteddate + interval '".VAULTRESTOREDAYS." days' else null end as restoreexpiredate ,propertyid ,tblarchive.clientcompanypropertyid ,coalesce((select stafffname||' '||stafflname as staffname from tblstaff where staffid = coalesce(p.propertylistingagent,pa.propertylistingagent)), pd.propertydeletelistingagent) as listingagent ,coalesce(coalesce(coalesce(coalesce(coalesce(pcd.clientcompanypropertydeleteassignmenttype,pca.clientcompanypropertyassignmenttype),pc.clientcompanypropertyassignmenttype),p.propertyassignmenttype),pa.propertyassignmenttype),pd.propertydeleteassignmenttype) as assignmenttype ,coalesce(coalesce(coalesce(coalesce(coalesce(pcd.clientcompanypropertydeleteaddress,pca.clientcompanypropertyaddress),pc.clientcompanypropertyaddress),p.propertyaddress),pa.propertyaddress),pd.propertydeleteaddress) as address ,coalesce(coalesce(coalesce(coalesce(coalesce(pcd.clientcompanypropertydeletecity,pca.clientcompanypropertycity),pc.clientcompanypropertycity),p.propertycity),pa.propertycity),pd.propertydeletecity) as city ,coalesce(coalesce(coalesce(coalesce(coalesce(pcd.clientcompanypropertydeletestate,pca.clientcompanypropertystate),pc.clientcompanypropertystate),p.propertystate),pa.propertystate),pd.propertydeletestate) as state ,case when propertyid > 0 then '/property_viewedit.php?view='||propertyid else '/property_viewedit.php?view='||tblarchive.clientcompanypropertyid end as propertyhref ,case when propertyid > 0 then '/vault.php?propertyid='||propertyid else '/vault.php?propertyid='||tblarchive.clientcompanypropertyid end as vaulthref ,archivestorethru::date as archivestorethru ,case when archivestorethru <= now() then '-1' else (archivestorethru::date-now()::date)::varchar||' days' end as daysleft , extract(month from archivecreateddate) as archivecreatedmonth , extract(year from archivecreateddate) as archivecreatedyear ,case when (archivestorethru-now()) < interval '".$vaultisextendableinterval."' then 1 else 0 end as vaultisextendable , case when archivestoreinterval <= interval '".VAULTSTOREDAYS_EXPORT." days' then 1 else 0 end as shorttermvault from tblarchive left join tblcompany using(companyid) left join tblproperty p using(propertyid, companyid) left join tblproperty_archive pa using(propertyid, companyid) left join tblpropertydelete pd on(propertydeleteoriginalid = propertyid) left join tblclientcompany on tblclientcompany.clientcompanyid = tblarchive.clientcompanyid left join tblclientcompanyproperty pc on pc.clientcompanypropertyid = tblarchive.clientcompanypropertyid left join tblclientcompanyproperty_archive pca on pca.clientcompanypropertyid = tblarchive.clientcompanypropertyid left join tblclientcompanypropertydelete pcd on(clientcompanypropertydeleteoriginalid = tblarchive.clientcompanypropertyid) where 0=0 and tblarchive.archivepurgeddate is null -- if it has been purged, dont return it - ever "; if($propertyid) $sql.=" and (tblarchive.propertyid = $propertyid or tblarchive.clientcompanypropertyid = $propertyid)"; if(vendorid()) { $sql.= " and exists (select 1 from tbltask where taskvendoridassigned = ".vendorid()." and pa.propertyid = propertyid)"; } if($companyid) $sql.=" and (tblarchive.companyid = $companyid or tblarchive.clientcompanyid = $companyid)"; if(companyid()) $sql.=" and tblarchive.companyid = ".companyid(); if(clientcompanyid()) $sql.=" and tblarchive.clientcompanyid = ".clientcompanyid(); if($type==expired) $sql.=" and archivestorethru < now() and archiverestorecompleteddate is null" ;//only return expired properties that have not been restored elseif(companyid() || clientcompanyid()) //for companies, do not show them expired items in their vault $sql.=" and ( ((archivestorethru + interval '".VAULTEXPIREBUFFERDAYS." days') > now()) ) " ;//only return not expired properties with VAULTEXPIREBUFFERDAYS days buffer if($extrasql) $sql .= $extrasql; if($limit) $sql .= " limit $limit "; //d(vault_getproperties_sql, $sql); $qry=db_query($sql); foreach($qry as $k=>$row) { $arr = vaultstatusarr($row); foreach($arr as $col=>$val) $qry[$k][$col]=$val; } if($propertyid>0) return $qry[0]; return $qry; } function vault_filepath($property,$type) { if(!is_array($property)) $property = vault_getproperties($property); if($type!=document && $type != photo && $type != details) return ""; if(!$property) return ""; $dr=$_SERVER[DOCUMENT_ROOT]; if ($property[clientcompanypropertyid]) $archive_dir = "../vault/client_{$property[clientcompanypropertyid]}/"; else $archive_dir = "../vault/$property[propertyid]/"; if(vendorid()) $added = "VENDOR_".vendorid()."_"; $filepath = "$dr/$archive_dir/$added$type.zip"; if(file_exists($filepath)) { //d(vault_filepath_exists, $filepath); return $filepath; } else { //d(vault_filepath_doesnt_exists, $filepath); } return ""; } /** * @name vault_filesonremote($archiverow) * @description Checks the remote storage (amazon) to see if the file has been uploaded. * @param array $archiverow * @explain_param A row from tblarchive that will be used to determine what files to check for on the remote vault. * @return an array where element [0] will be true or false element [1] will contain the bucketname and [2] will contain info about the files on the remote vault: * @explain_return If all the files from the archive are on the remote file system true will be returned as element [0] of the array and false otherwise. * @explain_return Element [1] of the array will return the bucket name and element [2] of the array contains the filename on the local system, the bucket name and the filename on the remote vault. * @explain_return Element [0] is false then element [1] and element [2] might not contain anything and shouldn't be relied on. * @example */ function vault_filesonremote($archiverow=FALSE) { $vaultdir=VAULTDIR; $retarray=array(); if(!$archiverow) return $retarray[0]=FALSE; if(!is_array($archiverow)) return $retarray[0]=FALSE; if($archiverow[clientcompanypropertyid]) $foldername="client_{$archiverow[clientcompanypropertyid]}"; else { if($archiverow[propertyid]) $foldername="$archiverow[propertyid]"; else return $retarray[0]=FALSE; } $bucketname="riovault"; $retarray[1]=$bucketname; $added=""; if(vendorid()) $added = "VENDOR_".vendorid()."_"; //Get connection to amazon remote storage if(!$s3=vault_gets3connect()) return $retarray[0]=FALSE; $retarray[0]=TRUE; for($i=1; $i<=3; $i++) { if($i==1) $type='document'; if($i==2) $type='photo'; if($i==3) $type='details'; $vaultfilepath = "$vaultdir$foldername/$added$type.zip"; $vaultfilename="$added$type.zip"; $vaultfolderfilename="$foldername/$vaultfilename"; if (($vaultfileinfo = $s3->getObjectInfo($bucketname, $vaultfolderfilename)) !== false) { $retarray[2][$i]['vaultfilepath']=$vaultfilepath; $retarray[2][$i]['vaultfilename']=$vaultfolderfilename; $retarray[2][$i]['vaultfiletype']=$type.".zip"; } else { if(file_exists($vaultfilepath)) { $retarray[0]=FALSE; return $retarray; } } } return $retarray; } /** * @name vault_remotefilepath($property,$type) * @description Checks the remote storage (amazon) to see if the file has been uploaded. * @param array $property * @explain_param The property that was archived. * @param string $type * @explain_param The type of zip file we are looking for and should be photo, document, or description. * @return false if the file not found, an array with the three follwing pieces of information: * @explain_return vaultfilepath: path to file on local system. bucketname: folder on remote location. * @explain_return vaultfilename: name of local and remote file. * @example */ function vault_remotefilepath($property,$type) { $vaultdir=VAULTDIR; if ($property[clientcompanypropertyid]) { $checkuploadtocloud=db_first("select archiveid from tblarchive where clientcompanypropertyid=$property[clientcompanypropertyid] and archiveuploadedtoclouddate is not null"); if(!$checkuploadtocloud) return false; $foldername="client_{$property[clientcompanypropertyid]}"; } else { $checkuploadtocloud=db_first("select archiveid from tblarchive where propertyid=$property[propertyid] and archiveuploadedtoclouddate is not null"); if(!$checkuploadtocloud) return false; $foldername="$property[propertyid]"; } $added=""; if(vendorid()) $added = "VENDOR_".vendorid()."_"; if(!is_array($property)) $property = vault_getproperties($property); //Get connection to amazon remote storage if(!$s3=vault_gets3connect()) { return false; } if($type!=document && $type != photo && $type != details) { return false; } if (!is_dir($vaultdir.$foldername)) if (!mkdir_wrapper($vaultdir.$foldername)) ddie("Unable to make directory"); $vaultfilepath = "$vaultdir$foldername/$added$type.zip"; $vaultfilename="$added$type.zip"; $vaultfolderfilename="$foldername/$vaultfilename"; $bucketname="riovault"; if (($vaultfileinfo = $s3->getObjectInfo($bucketname, $vaultfolderfilename)) !== false) { $retarray['vaultfilepath']=$vaultfilepath; $retarray['bucketname']=$bucketname; $retarray['vaultfilename']=$vaultfolderfilename; return $retarray; } return false; } function vault_payment($paymentdescr, $paymentamount,$addedfields=array()) { global $ACCEPTED_CREDITCARDS, $TESTCC; $testcc=$TESTCC; $submitted = $_POST[ccnumber]; $qrycc = db_first("select * from tblsavedcc where loginid = ".loginid()); // below not checked into task replaced with below code on live JT //if($qrycc) //{ // $ccnumber = decrypt_cc($qrycc[savedccnumber]); // $ccnumber_display4 = $ccnumber; // //$ccnumber_display4 = str_pad(substr($ccnumber,-4),strlen($ccnumber),"*",STR_PAD_LEFT); //} if($qrycc) { $ccnumber = decrypt_cc($qrycc[savedccnumber]); //$ccnumber_display4 = $ccnumber; $ccnumber_display4 = str_pad(substr($ccnumber,-4),strlen($ccnumber),"*",STR_PAD_LEFT); } if((has_access("vaultskippayment") && $_POST[skippayment]) || ($_POST[ccnumber] && ($_POST[ccnumber] == $testcc && !is_livesite()))) { //they have permission and have requested to skip payment //lets build an arracy that can be returned to the receipt for processing $skipped = "Skipped Payment"; $retarr[description] = $paymentdescr; $retarr[amount] = 0; $retarr[success] = $skipped; $retarr[cardholder] = $skipped; return $retarr; } if($submitted) { if($_POST[ccnumber]) { $_POST[ccnumber] = str_replace(" ","",$_POST[ccnumber]); $_POST[ccnumber] = str_replace("-","",$_POST[ccnumber]); } if($_POST[ccuseonfile] && $qrycc); //dont check the cc numberif they are using the cc on account. elseif(strlen($_POST[ccnumber])<15||strlen($_POST[ccnumber])>16||!is_numeric($_POST[ccnumber])) $errormsg.="
Please enter a valid Credit Card Number"; if((strtotime("$_POST[ccexpyear]-$_POST[ccexpmo]-1")+3600*24*30)< time()) // make sure the credit card only expired less than 30 days ago $errormsg.="
Please enter an expiration in the future"; if(strlen(trim($_POST[ccname]))<3) $errormsg.="
Please enter the Name on the Card"; if(is_array($addedfields)) foreach($addedfields as $field) if(!$_POST[$field[fieldname]]) $errormsg.="
Please enter a value for $field[label]"; if(!$errormsg && !$paymentamount) $errormsg.="
DEVELOPER CONFIGURATION ERROR: \$paymentamount not passed into vault_payment(functions_payment:".__LINE__.")"; } echo ""; if($submitted && !$errormsg && $_POST[ccverifyreviewed]) { //processcc $ccarr=array(); //initialize array empty $ccarr[card] = $_POST[ccnumber]; if($_POST[ccuseonfile] && $qrycc) //user the cc on file $ccarr[card] = decrypt_cc($qrycc[savedccnumber]); $ccarr[exp] = $_POST[ccexpmo].$_POST[ccexpyear]; $ccarr[cardholder] = $_POST[ccname]; $ccarr[description]=$paymentdescr; //Hotfix - The code below needs to be removed after QA finishes testing on joetest and hannibalsmith. This is a part of task 22162 - Unable to vault. 11/03/2015 //if(is_developer() && (loginid()==35945 or loginid()==49622 or loginid()==49625)) // $_POST[skippayment] = 1; // This is a hack to be able to vault property without the cc if((is_devsite() || is_developer()) && $_POST[skippayment]) { $retarr[success]= "ok"; } else $retarr = process_cc($ccarr, $paymentamount, vault,1); $errormsg = $retarr[errormessage]; $ccnumber = encrypt_cc($ccarr[card] ); if($retarr[success]) { if (clientcompanyid()) $sql = "insert into tblpurchase (clientcompanyid,purchaseamount,purchaseauthorization,purchasedescription, purchaseccnumber, purchaseccexpiredate, purchaseccname) values (".clientcompanyid().",$paymentamount,'$retarr[authorization_number]','".db_col($retarr[description])."', '$ccnumber','$retarr[exp]', '$_POST[ccname]')"; else $sql = "insert into tblpurchase (companyid,purchaseamount,purchaseauthorization,purchasedescription, purchaseccnumber, purchaseccexpiredate, purchaseccname) values (".companyid().",$paymentamount,'$retarr[authorization_number]','".db_col($retarr[description])."', '$ccnumber','$retarr[exp]', '$_POST[ccname]')"; db_exec($sql); if($_POST[ccsavetoaccount]) { $qrycc = db_first("select * from tblsavedcc where loginid = ".loginid()); if($qrycc[savedccid]) $sql = "update tblsavedcc set savedccname = '".db_col($_POST[ccname])."' , savedccnumber = '$ccnumber' , savedccexpmo = '$_POST[ccexpmo]' , savedccexpyear = '$_POST[ccexpyear]' , savedcctype = '$_POST[cctype]' where savedccid = $qrycc[savedccid] "; else $sql = "insert into tblsavedcc(loginid,savedccnumber,savedccname, savedccexpmo, savedccexpyear, savedcctype) values (".loginid().",'$ccnumber','".db_col($_POST[ccname])."','$_POST[ccexpmo]','$_POST[ccexpyear]','$_POST[cctype]')"; d($sql); db_exec($sql); } return $retarr; } //uncomment this to sent back a positive result (which makes the code return true) //good for testing, bad for denying service on failed charges :) //return $retarr; } if($submitted && !$errormsg) { if($_POST[ccuseonfile] && $qrycc) $_POST[ccnumber] = $ccnumber_display4 ; ?> "; if(is_array($addedfields)) { foreach($addedfields as $field) { if(!$field[fieldname]) ddie("invalid field configuraiton functions_vault:".__LINE__." (no fieldname specified",$field); echo "\n"; if($field[label]) echo ""; echo ""; } } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if(substr($paymentdescr,0,4)!= "Bulk") echo "\n"; ?>

Verify your payment information

$field[label]"; else echo ""; $value=$_POST[$field[fieldname]]; if($field[display]) $value=str_replace("VALUE",$value,$field[display]); echo $value; echo "
Description$paymentdescr
Credit Card".$ACCEPTED_CREDITCARDS[$_POST[cctype]]."
Name on the Card$_POST[ccname]
Card Number$_POST[ccnumber]
Expiration Date$_POST[ccexpmo]/$_POST[ccexpyear]
Billing Address$_POST[ccaddress]
City$_POST[cccity]
State / Zip$_POST[ccstate] / $_POST[cczip]
Payment Amount$".number_format($paymentamount,2)."
 
($".number_format($paymentamount,2)." will be charged to your account when you click 'Make Payment'
 
$value) if(substr($name,0,2)==cc) echo "\n"; if(is_array($addedfields)) foreach($addedfields as $field) echo "\n"; } else //if we should show the form { ?> "; if($field[label]) echo ""; echo ""; } } if(has_access("vaultskippayment") || (is_devsite() && 1 == 2)) { echo ""; } if (is_devsite()) { if (!$_POST[ccname]) $_POST[ccname] = "El Presidente de Spain"; if (!$_POST[ccnumber]) $_POST[ccnumber] = $testcc; if (!$_POST[ccexpyear]) $_POST[ccexpyear] = 20; } ?> "; ?>

Enter your payment information

Use card on file >to use your credit card on file (ending in )
* = Required Field

$field[label]"; else echo ""; echo $field[field]; echo "
Overseer user only: Skip Payment "; if (is_devsite() && !is_admin()) d('Hey Dev, this is a vaultskippayment override so you can archive without entering a CC.') ?>

Payment Amount $".number_format($paymentamount,2)."
Credit Card:*
Name on the Card:* >
Credit Card Number:* style='width:120px;' value=''> (no dashes)
Expiration Date:*  / 
Billing Address:* >
City:* >
State/Zip:* /
Save this Credit Card >
This card would show next time you purchase
something through the vault

(you will be able verify your informaton in the next step)
subbutton=document.getElementById('submitbutton'); if(subbutton!=null && typeof(subbutton)!='undefined') setTimeout(\"document.getElementById('submitbutton').focus()\",10); "; } return false; } function get_propertyphotos($propertyid, $client_prefix="") { if (empty($propertyid)) { d(____WARNING__The_propertyid_is_zero_get_propertyphotos); return; } if ($client_prefix) { $sql = "select * from tblimage join tbllogin on loginid = imageloadedby where clientcompanypropertyid = $propertyid or clienttaskid in (select clienttaskid from tblclienttask where clientcompanypropertyid = $propertyid)"; } else { $sql = "select * from tblimage join tbllogin on loginid = imageloadedby where propertyid = $propertyid or taskid in (select taskid from tbltask where propertyid = $propertyid)"; } $qryphoto = db_query($sql,1,0,imageid); //d($qryphoto); $zips=array(); foreach($qryphoto as $pid=>$prow) { $vendorid=$prow[vendorid]; if($vendorid) $zips[vendor][$vendorid][$pid] = "photos/".getrelativephotodir($pid) ; $zips[photo] [$pid] = "photos/".getrelativephotodir($pid); } return $zips; } /** * @name get_propertydocuments * @param integer $propertyid * @param string $client_prefix * @return void|Ambigous */ function get_propertydocuments($propertyid, $client_prefix="") { if (empty($propertyid)) { d(____WARNING__The_propertyid_is_zero_get_propertydocuments); return; } if ($client_prefix) { $sql = "select * from tbldocument where clientcompanypropertyid = $propertyid or clienttaskid in (select clienttaskid from tblclienttask where clientcompanypropertyid = $propertyid) "; } else { $sql = "select * from tmp_property_documents t join tbldocument using(documentid) left join tbllogin on loginid = documentloadedby where t.{$client_prefix}propertyid = $propertyid"; } $qrydoc = db_query($sql,1,0,documentid); $zips=array(); foreach($qrydoc as $did=>$drow) { $vendorid=$drow[vendorid]; if($vendorid) $zips[vendor][$vendorid][$did] = "document/".getrelativedocumentdir($did) ; $zips[document][$did] = "document/".getrelativedocumentdir($did); } return $zips; } function create_archive($propertyid,$type,$hier,$arr,$vendorid=0,$client_prefix="") { if (empty($propertyid)) { d(____WARNING__The_propertyid_is_zero_create_archive); return; } //$hier=the type of hierarchy to create (simple or complex) complex has folders for each item, simple has files named with the unique folder entry $dr = $_SERVER[DOCUMENT_ROOT]; $fname = get_archivezipfilename($archive_dir,$type,$vendorid); $vdir = VAULTDIR.$client_prefix."$propertyid/"; $fullpath = "$vdir$fname"; $tempdir = "/tmp/$type".time()."r".rand(10000,100000); //create the temporary archive location that will be zipped up if (!$arr)// catch for empty $arr=array(); elseif (!is_array($arr)) ddie("Developer error var arr is not array:".$arr); // This is to catch if we pass arr as non array. @mkdir_wrapper($tempdir); @mkdir_wrapper($vdir); d(fullpath,$fullpath); d(__arr__, $arr); foreach($arr as $id=>$path) { if(!is_dir("$dr/$path")) { d(__skipped_not_path_); continue; } $cmd=""; if($hier==complex) //complex means they have a separate folder for each item $cmd = "rm '$dr/$path/docpreview*'; cp -r '$dr/$path' $tempdir/$id; "; elseif($hier==details) // copy all csv files into the root tmp folder { $cmd = "rm '$dr/$path/docpreview*'; cp -r '$dr/$path' $tempdir; "; } else //simple means all documents are in the root folder with the id in from of the item { d(_path_, $path); $d = dir("$dr/$path"); if($d) while($fpath=$d->read()) if($fpath!="."&&$fpath!="..") if(!strstr($fpath,docpreview)) $cmd .= "mkdir -p $tempdir/; cp '$dr/$path/$fpath' '$tempdir/{$id}__$fpath' ; "; } if($cmd) { $status = system($cmd, $results); //dlog(zip_create, __Start_Command); //dlog(zip_create, 'cmd:'.$cmd); //dlog(zip_create, 'status:'.$status); //dlog(zip_create, 'results: '.$results); d(cmd,$cmd); d(zip_create_cmd, $cmd); d(zip_create_status, $status); d(zip_create_results, $results); } else { d(cmd_command_was_empty, cmd_command_was_empty.$propertyid); dlog(zip_create, cmd_command_was_empty.$propertyid); } } d(__before__, scandir($tempdir)); $cmd = "mv $fullpath $fullpath.".time().".bk; cd $tempdir; /usr/bin/zip -ur -9 $fullpath .; "; d(__after__, scandir($tempdir)); d(zipcmd, $cmd); system($cmd); $verifiedzipped = get_zippedfileidlist($fullpath); d(zipped, $verifiedzipped); foreach($arr as $id=>$path) { if($verifiedzipped[$id]) { $sql=""; //if we found that the file was located in the archive, we can comfortably update the record in the database to say that it is archived. //then we can run a query to check to find all images that should be archived where the tblproperty DOES NOT exist and delete the files. if ($type==photo) $sql = "update tblimage set imagearchiveddate = now() where imageid =$id"; elseif($type == document) $sql = "update tbldocument set documentarchiveddate = now() where documentid =$id"; elseif($type == details) ; // ignore don't have to update anything for csv if($sql) db_exec($sql); d(__loop___, $sql); } } $cmd= "rm -r -f $tempdir;"; d(rmcmd,$cmd); //system($cmd); } function get_zippedfileidlist($pth) { $cmd = "/usr/bin/unzip -l $pth ; "; $out = `$cmd`; $lines=explode("\n",$out); //d($lines); foreach($lines as $line) { $line=str_replace(" ", " ",$line); $line=str_replace(" ", " ",$line); $line=str_replace(" ", " ",$line); $line=str_replace(" ", " ",$line); $larr = explode(" ",$line); $fileid = $larr[4]; $fileid = list_first($fileid,"/"); $fileid = list_first($fileid,"_"); if(is_numeric($fileid)) $fileids[$fileid]=$fileid; } return $fileids; } function extract_archive($propertyid,$type,$vendorid=0,$client_prefix="") //we'll most likely NEVER extract vendor, but the capability is here. { if (empty($propertyid)) { d(____WARNING__The_propertyid_is_zero_extract_archive); return; } $vd = VAULTDIR; $dr = $_SERVER[DOCUMENT_ROOT]; $fname = get_archivezipfilename($client_prefix.$propertyid,$type,$vendorid); $bucketname="riovault"; //Check to see if the file is on local filesystem, if not then check amazon for file and if the file is there copy it to local filesystem. if(!file_exists("$vd$fname")){ if($s3=vault_gets3connect()) { $foldername=$client_prefix.$propertyid; $vaultfilename=str_replace("$foldername/","",$fname); $foundonremote=FALSE; if (($vaultfileinfo = $s3->getObjectInfo($bucketname, $fname)) !== false) { $foundonremote=TRUE; } if($foundonremote) { //d("Found The file on the remote server $vd$fname."); $vaultfp = fopen("$vd$fname", "wb"); if (($vaultfilereturn = $s3->getObject($bucketname, $fname, $vaultfp)) !== false) { $vaultfilereturninfo = $s3->getObjectInfo($bucketname, $fname); $touchmtime=date("YmdHi", $vaultfilereturninfo['time']); $cmd="touch -t $touchmtime '$vd$fname'"; //d('cmd',$cmd); system($cmd); //d("got file: $fname in bucket: $bucketname from Amazon and now ready to save it locally to: $fname"); //exit; } } } } $tempdir = "/tmp/extract".time()."r".rand(10000,100000); //create the temporary archive location that will be zipped up @mkdir_wrapper($tempdir); $cmd = "cd $tempdir; unzip $vd$fname ; "; d($cmd); system($cmd); $d = dir($tempdir); while($fname=$d->read()) { if($fname=="." || $fname=="..") continue; $fexp = explode("_",$fname); $func = "getrelative{$type}dir"; $destdir = $func($fexp[0]); $id = $fexp[0]; if(!is_numeric($id)) continue; if(is_dir("$tempdir/$fname")) //this is a directory { $fromfilename="$fname/*"; //mv all the files in the dir to the . directory under the item folder $destfilename="."; } else // this is a file { $fromfilename="$fname"; //mv the entire filename from the root folder to the new file name under the document folder $destfilename=str_replace("{$fexp[0]}__","",$fname); // } $tdir = $type; if($type==photo) $tdir = photos; $cmd = "cd $tempdir; mkdir -p $dr/$tdir/$destdir; mv $fromfilename $dr/$tdir/$destdir/$destfilename ;"; d($cmd); system($cmd); $sql=""; //if we found that the file was located in the archive, we can comfortably update the record in the database to say that it is archived. //then we can run a query to check to find all images that should be archived where the tblproperty DOES NOT exist and delete the files. $filecnt = isorhasfiles("$dr/$tdir/$destdir/$destfilename"); //d(fs,$cnt); if($filecnt) { //looks like we were able to extract some files to the directory //lets mark the file not archived any more. if ($type==photo) $sql = "update tblimage set imagearchiveddate = null , imagedirdeleteddate = null where imageid =$id"; elseif($type == document) $sql = "update tbldocument set documentarchiveddate = null, documentdirdeleteddate = null where documentid =$id"; if($sql) db_exec($sql); } } $cmd = "rm -rf $tempdir;"; d($cmd); system($cmd); } function isorhasfiles($d) { if(!is_dir($d)) return is_file($d); $d=dir($d); while($f=$d->read()) if($f!="."&&$f!="..") $cnt++; return $cnt; } /** * @name vault_gets3connect() * @description Sets up the connection to the amazon remote storage * @return false if you cannot connect or an s3 object that you can use to get and send files to amazon remote storage. * @example */ function vault_gets3connect() { if (!class_exists('S3')) require_once ("$_SERVER[DOCUMENT_ROOT]/_inc/S3.php"); // AWS access info if (!defined('awsaccesskey')) return false; if (!defined('awssecretkey')) return false; // Check for CURL if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll')) return false; // Instantiate the class $s3 = new S3(awsaccesskey, awssecretkey); return $s3; } /** * @name vault_getbucketarray($bucketname, $s3) * @description Checks the remote storage (amazon) to see if the file has been uploaded. * @param $bucketname The name of the bucket on Amazon server to delete. * @explain_param A row from tblarchive that will be used to determine what files to check for on the remote vault. * @param $s3 A connection object to the Amazon S3 server * @return an array containing the name and modified time of each object in the bucket or an empty array if the bucket is empty or doesn't exist. * @example 0) {echo 'we have the info on files in the bucket';} ?> */ function vault_getbucketarray($bucketname, $s3) { $retarray=array(); if($bucketname=="") return $retarray; if(($contents = $s3->getBucket($bucketname)) !== false) { foreach($contents as $amazonvaultfile) { $amazonvaultfilename=$amazonvaultfile['name']; $retarray[$amazonvaultfilename]['name']=$amazonvaultfile['name']; $retarray[$amazonvaultfilename]['mtime']=$amazonvaultfile['time']; } //d("retarray: ",$retarray); } return $retarray; } /** * @name vault_deletebucket($bucketname, $s3) * @description Deletes all the files in the bucket then removes the bucket. * @param $bucketname The name of the bucket on Amazon server to delete. * @explain_param A row from tblarchive that will be used to determine what files to check for on the remote vault. * @param $s3 A connection object to the Amazon S3 server * @return retruns true if delete completed and false otherwise. * @example */ function vault_deletebucket($bucketname, $s3) { //Way to delete bucket. You first have to delete everything inside the bucket. if(($contents = $s3->getBucket($bucketname)) !== false) { foreach($contents as $amazonvaultfile) $s3->deleteObject($bucketname, $amazonvaultfile['name']); } if(($s3->deleteBucket($bucketname)) !== false) return TRUE; else return FALSE; } /** * @name vault_fileexists($prop, $type) * @description Checks to see if the type of file is on the local file system or the remote file system. * @param $prop An array containing information about the property. * @param $type The type of vaulted file (photo,document,details) * @return retruns a string with the filepath if the file is on local, an array with bucket info if only on vault, or false otherwise. * @example */ function vault_fileexists($prop, $type) { if(!$prop) return FALSE; if($type && $type!='') { if(vault_filepath($prop,$type)) return TRUE; if(vault_remotefilepath($prop,$type)) return TRUE; } return FALSE; } /** * @name pull_delegations_to_and_from_vaulted_clientcompanyproperty($clientcompanypropertyid) * @description Pulls the delegations to and from a vaulted clientcompanyproperty and adds explanatory notes to any affected properties. * @param $clientcompanypropertyid The clientcompanypropertyid. * @return retruns TRUE. * @example */ function pull_delegations_to_and_from_vaulted_clientcompanyproperty($clientcompanypropertyid) { $delegationparent = getdelegationparent($clientcompanypropertyid); if($delegationparent) { //d('pulled parent',$delegationparent[delegationtoclientcompanypropertyid]); pulldelegation($delegationparent[delegationtoclientcompanypropertyid]); create_note($clientcompanypropertyid,clientcompanyproperty,"The Asset Management Company you delegated this property to has vaulted the property and the delegation has been removed.","","",1); } $delegationchildren = getdelegationchildren($clientcompanypropertyid); if($delegationchildren) { foreach($delegationchildren as $delegationchild) { //d('pulled child',$delegationchild[delegationtoclientcompanypropertyid]); pulldelegation($delegationchild[delegationtoclientcompanypropertyid]); create_note($clientcompanypropertyid,clientcompanyproperty,"The Asset Management Company who delegated this property to you has vaulted the property and the delegation has been removed.","","",1); } } return TRUE; }