1*$default_program, 'original_program' => 1*$default_program, 'webmaster' => 1*$no_credit_webmaster); } $hit = new Hit(); $hit->ip = getIP(); $hit->site=$site; $hit->tour=$tour; $hit->geoIP(); if (!$hit->exists()) { /* if ($conn->debug) echo "getting tracking info from mpa3v1"; $v1_db_user = 'migration'; $v1_db_pass = 'tarkan98'; $v1_db_host = '77.245.49.245'; $v1_db_name = 'mpa3'; $v1_conn = & ADONewConnection('mysql'); $v1_conn->NConnect($v1_db_host, $v1_db_user, $v1_db_pass, $v1_db_name); $v1_conn->Execute("SET NAMES utf8"); $v1_conn->debug = $conn->debug; $ipv4 = inet_aton($hit->ip); $sql = "select * from mpa3_hits WHERE ipv4=".(int)$ipv4." and site=".(int)$hit->site." and tour='$hit->tour' and visit_date>date_add(now() , INTERVAL -$ip_exp HOUR)"; $res = $v1_conn->GetRow($sql); if (count($res)<2) return array('program' => 1*$default_program, 'original_program' => 1*$default_program, 'webmaster' => 1*$no_credit_webmaster); else return $res; */ return array('program' => 1*$default_program, 'original_program' => 1*$default_program, 'webmaster' => 1*$no_credit_webmaster); } else { return array('site' => $site, 'webmaster' => 1*$hit->webmaster, 'program' => 1*$hit->program, 'original_program' => 1*$hit->original_program, 'campaign' => $hit->campaign, 'referrer' => $hit->referrer, 'fm' => $hit->fm, 'cexit' => $hit->cexit, 'console' => $hit->console, 'tour' => $hit->tour ); } return array('site' => $site, 'webmaster' => 1*$webmaster, 'program' => 1*$program, 'original_program' => 1*$program, 'campaign' => $campaign, 'referrer' => $referrer, 'fm' => 1*$fm, 'cexit' => $cexit, 'console' => $console, 'tour' => $tour ); } / Bellow are the functions for two-toier tracking function wm_cookie($webmaster, $referralId, $campaign='') { global $_COOKIE, $_SERVER, $rfr, $cookie_exp,$HTTP_HOST; / the $cookie_exp is not set in the config.php no cookies are working if (!preg_match("/[0-9]+/", $cookie_exp)) $cookie_exp = 1; $domain = $_SERVER['HTTP_HOST']; $domain = explode('.',$domain); $domain = '.'.$domain[count($domain)-2].'.'.$domain[count($domain)-1]; $cookie_name="twotier"; $cookie_val = "$webmaster##$referralId##$campaign"; if ($_SERVER['HTTP_HOST']== "localhost"){ setcookie($cookie_name, $cookie_val); } else { setcookie($cookie_name, $cookie_val, time()+3600*$cookie_exp,'/',"$domain"); } } function wm_info() { global $_COOKIE; $webmaster = 0; if ($_COOKIE[twotier]) { list($webmaster, $referralId, $campaign)= explode("##", $_COOKIE["twotier"]); } else { include_once(CLASSES_PATH."wm_hit.class.php"); $hit = new WMHit(); $hit->ip = getIP(); $hit->geoIP(); if (!$hit->exists()) { return null; } else { return array($hit->webmaster, 0); } } return array($webmaster, $referralId, $campaign); } ?>$value) $this->$key = $value; $this->sql= $sql; $this->fm = 1*$this->fm; include_once(CLASSES_PATH."site.class.php"); $site = new Site($this->site); $this->master_site = $site->master_site; unset($site); $this->Process_SQL($input); return 1; } public function Process_SQL($input=null) { $exists = $this->exists(); if (is_array($input)) foreach ($input as $key=>$value) $this->$key = $value; $this->unique = !$exists; $this->visit_date = date("Y-m-d H:i:s"); $this->date = date("Y-m-d"); if ($exists) { $this->update(get_object_vars($this)); } else { $this->create(); } if ($this->unique) { include_once(CLASSES_PATH."stats.class.php"); $stats = new PrgUniqueStats($this); $stats->add_unique(); } else { include_once(CLASSES_PATH."stats.class.php"); $stats = new PrgUniqueStats($this); $stats->add_raw(); } return 1; } public function create() { global $conn; if ($this->id) return 0; $sql = "SELECT * FROM ".TBL_PREFIX."hits WHERE id = -1"; $result = $conn->Execute($sql); $obj_vars = $result->FetchObj(); foreach($obj_vars as $var=>$val) if (! isset($this->$var)) $this->$var = ''; if ($conn->no_autoincrement) $this->id = $conn->GenID("seq_".TBL_PREFIX."hits",1); $insertSQL = $conn->GetInsertSQL($result, get_object_vars($this)); $conn->Execute($insertSQL); if (! $this->id) $this->id = $conn->Insert_ID(); } public function read() { global $conn, $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $query = "SELECT * from ".TBL_PREFIX."hits where id='".$this->id."'"; $result = $conn->GetAll($query); if (! is_array($result[0])) return 0; $row = $result[0]; foreach ($result[0] as $property_name=>$value) { $this->$property_name = $row[$property_name]; } } public function save() { global $conn; $sql = "SELECT * FROM ".TBL_PREFIX."hits WHERE id = '".$this->id."'"; $result = $conn->Execute($sql); $obj_vars = $result->FetchObj(); foreach($obj_vars as $var=>$val) if (! isset($this->$var)) $this->$var = ''; $updateSQL = $conn->GetUpdateSQL($result, get_object_vars($this)); if ($updateSQL) $conn->Execute($updateSQL); } public function update($properties,$save_it=1) { if (! is_array($properties)) return 0; foreach($properties as $property=>$value) { if ($this->$property != $value) { $this->$property = $value; } } if ($save_it) $this->save(); } public function exists() { global $conn, $cookie_exp, $ip_exp; if (!is_numeric($ip_exp)) $ip_exp = $cookie_exp; if (!is_numeric($ip_exp)) $ip_exp = 1; if ($this->webmaster) $wm_criteria = "webmaster='$this->webmaster'"; else $wm_criteria = "1"; $query = "SELECT max(id) as id FROM ".TBL_PREFIX."hits WHERE ipv4=".(int)$this->ipv4." and site=".(int)$this->site." and tour='$this->tour' and $wm_criteria and visit_date>date_add(now() , INTERVAL -$ip_exp HOUR)"; $result = $conn->GetAll($query); if (! is_array($result[0])) return 0; if ((int)$result[0]['id']==0) return 0; $row = $result[0]; $this->id = $row[id]; $this->read(); $this->unique = 0; return 1; } public function GeoIP() { global $conn, $ADODB_FETCH_MODE; include_once(FUNCTIONS_PATH."ip_funcs.php"); $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $this->ipv4 = inet_aton($this->ip); $query = "SELECT code2,name FROM ".TBL_PREFIX."geoip WHERE beg_ip<=$this->ipv4 AND end_ip>=$this->ipv4"; $result = $conn->GetAll($query); if (! is_array($result[0])) $result[0] = array('code2'=>'XX','code3'=>'XXX','name'=>'UNKNOWN'); $row = $result[0]; foreach ($row as $property_name=>$value) { $this->$property_name = $value; } } public function is_unique() { return $this->unique; } public function getCountry($code='code2') { return $this->$code; } public function toString($delimiter = "\n
\n") { $asArray = get_object_vars($this); foreach ($asArray as $key=>$val) $str.="\$$key='$val'".$delimiter; return $str; } } ?>read($id); return 1; } public function read($id=null) { / Reads the info from the database and sets the properties, if no id reads for the current $this->id global $conn; if ($id) { $this->id = $id; } if (DB_IS_DOWN === true) { $objSite = FileStorage::getSiteObject($this->id); if (!is_null($objSite)) { $objVars = get_object_vars($objSite); foreach($objVars as $key => $value) { $this->$key = $value; } } } else { $query = "SELECT * from ".TBL_PREFIX."sites where id=".$this->id; $result = $conn->GetAll($query); if (! is_array($result[0])) { return null; } $row = array_change_key_case($result[0], CASE_LOWER); foreach ($row as $property_name=>$value) { $this->$property_name = $value; } } if ($this->master_site == 0 && $this->id > 0) { $this->master_site = $this->id; } } public function save() { / Saves into the database global $conn; if (!$this->id) { $this->id = $this->siteID; } $sql = "SELECT * FROM ".TBL_PREFIX."sites WHERE id = ".$this->id; $result = $conn->Execute($sql); $obj_vars = $result->FetchObj(); foreach ($obj_vars as $var=>$val) { if (!isset($this->$var)) { $this->$var = ''; } } $updateSQL = $conn->GetUpdateSQL($result, get_object_vars($this), true, true, true); if ($updateSQL) { $conn->Execute($updateSQL); } / sites data to a php file FileStorage::storeSitesData(); } public function update($properties,$save_it=1) { global $conn; / array of pairs property=>value to be updated, always use with caution, / the update form is the preferred method foreach($properties as $property=>$value) { $this->$property = $value; } if ($save_it) $this->save(); } public function create($properties) { / sets the properties, saves into the database, gets the id and sets it global $conn; require_once(FUNCTIONS_PATH."execute_funcs.php"); $asArray = get_object_vars($this); foreach ($asArray as $property_name=>$value) { $this->$property_name = $properties[$property_name].''; } $sql = "SELECT * FROM ".TBL_PREFIX."sites WHERE id = -1"; $result = $conn->Execute($sql); $obj_vars = $result->FetchObj(); foreach($obj_vars as $var=>$val) if (! isset($this->$var)) $this->$var = ''; $this->deleted = 0; if ($conn->no_autoincrement) $this->id = $conn->GenID("seq_".TBL_PREFIX."sites",1); $signup_dir = SIGNUP_PATH.$this->id; if(!is_dir($signup_dir)) { $templates_dir = SIGNUP_PATH.'templates'; if(!is_dir($signup_dir)) $command = execute("cp -rf $templates_dir $signup_dir"); ($signup_dir, 0777); } $insertSQL = $conn->GetInsertSQL($result, get_object_vars($this)); $conn->Execute($insertSQL); if (! $this->id) {$this->id = $conn->Insert_ID();} if (! $this->master_site) {$this->master_site = $this->id; $this->save();} } public function addMember($username,$password,$email=null) { / Self explanatory global $conn; / there is no member management script set, act as if it's all ok if ($this->adp=='' || $username=='' || $password=='') return 1; / if the adp url is on the same server where mpa3 is and connects directly to the db if (!(strpos($this->adp, PROGRAM_URL)===false) && strstr($this->htpasswd,'|')) { $conn_adp = &$this->build_conn(); $sql = "delete from $this->adp_tablename where $this->adp_username_field='$username'"; $res = $conn_adp->GetOne($sql); $sql = "insert into $this->adp_tablename ($this->adp_username_field,$this->adp_password_field) values('$username',$this->enc_method('$password'))"; $res = $conn_adp->GetOne($sql); return 1; } require_once(FUNCTIONS_PATH."http_post.php"); if (strstr($this->htpasswd,'|')) $command = "data=ADD,$this->htpasswd,$username,$password,$email"; else $command = "ADD,$this->htpasswd,$username,$password"; if ($conn->debug) $conn->outp('curl -k -d \''.$command.'\' '.$this->adp."\n"); / ." -k -d 'ADD,$this->htpasswd,$username,$password' $this->adp $res = http_post($this->adp,$command); if ($conn->debug) $conn->outp($res."\n"); if (strstr($res,'ADDED')) return 1; else return 0; } public function deleteMember($username) { / Self explanatory global $conn; / there is no member management script set, act as if it's all ok if ($this->adp=='') return 1; / if the adp url is on the same server where mpa3 is and connects directly to the db if (!(strpos($this->adp, PROGRAM_URL)===false) && strstr($this->htpasswd,'|')) { $conn_adp = &$this->build_conn(); $sql = "delete from $this->adp_tablename where $this->adp_username_field='$username'"; $res = $conn_adp->GetOne($sql); return 1; } require_once(FUNCTIONS_PATH."http_post.php"); if (strstr($this->htpasswd,'|')) $command = "data=DELETE,$this->htpasswd,$username"; else $command = "DELETE,$this->htpasswd,$username"; if ($conn->debug) $conn->outp($command."\n"); $res = http_post($this->adp,$command); if ($res=="DELETED $username") return 1; else return 0; } public function &build_conn() { global $conn; $credentials = explode("|", $this->htpasswd); $this->adp_host=$credentials[0]; $this->adp_user=$credentials[1]; $this->adp_pass=$credentials[2]; $this->adp_db=$credentials[3]; $this->adp_tablename=$credentials[4]; $this->adp_username_field=$credentials[5]; $this->adp_password_field=$credentials[6]; $conn_adp = &NewADOConnection('mysql'); $conn_adp->debug=$conn->debug; $conn_adp->Connect($this->adp_host, $this->adp_user, $this->adp_pass, $this->adp_db); return $conn_adp; } public function checkMember($username) { / Self explanatory global $conn; / there is no member management script set, act as if it's all ok if ($this->adp=='') return 0; / if the adp url is on the same server where mpa3 is and connects directly to the db if (!(strpos($this->adp, PROGRAM_URL)===false) && strstr($this->htpasswd,'|')) { $conn_adp = &$this->build_conn(); $sql = "select count(*) from $this->adp_tablename where $this->adp_username_field='$username'"; $res = $conn_adp->GetOne($sql); if ($res) return 1; else return 0; } require_once(FUNCTIONS_PATH."http_post.php"); if (strstr($this->htpasswd,'|')) $command = "data=CHECK,$this->htpasswd,$username"; else $command = "CHECK,$this->htpasswd,$username"; if ($conn->debug) $conn->outp($command."\n"); $res = http_post($this->adp,$command); / theere is no FOUND string, it means the password management script is not accessible. / as if the username was not found, or the member won't be able to proceed and signup if (!preg_match("/FOUND/", $res)) return 0; if ( strstr($res,'NOT_FOUND')) return 0; else return 1; } public function refreshMemberAccess($username,$password,$email=null) { $this->addMember($username,$password,$email); } function refreshAll() { global $conn, $ADODB_FETCH_MODE; $query = "SELECT username,password,email from ".TBL_PREFIX."members where site=".$this->id." or site=0"; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $result = $conn->GetAll($query); foreach ($result as $row) { $this->refreshMemberAccess($row[username],$row[password],$row[email]); } } public function deleteExpired() { global $conn, $ADODB_FETCH_MODE; $query = "SELECT username from ".TBL_PREFIX."members where (site=".$this->id." or site=0) and edate=date_add(now(),interval -3 day)"; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $result = $conn->GetAll($query); foreach ($result as $row) { $this->deleteMember($row[username]); } } public function copy($origin_id) { / Gets all settings from another site and sets them for the new one $currentID = $this->id; $currentMaster = $this->master_site; $currentTitle = $this->title; $origin = new Site($origin_id); foreach (get_object_vars($origin) as $key=>$val) $this->$key = $val; $this->id = $currentID; $this->master_site = $currentMaster; if ($currentTitle) $this->title = $currentTitle; $this->save(); unset($origin); $this->setPayRates($origin_id); } public function printForm() { / If a new site will show a blank form, otherwise will show prefilled form. Form is read from a template file / Webmasters select is generated here and initialized if it is necessary global $conn; /"lists_funcs.php"); / $form = implode('',file(INNER_TEMPLATES_PATH."sites.html")); / / = array("No", "Yes"); / = array ( 'active', 'visible', 'use_alternate', 'trials' ); / = str_replace('{niche_select}',niche_select($this->niche),$form); / ( $fields as $key ) { / = ""; / ( $i = 0; $i <= 1; $i ++ ) { / = ""; / ( $i == $this->$key ) $selected = "selected"; / .= "\n"; / / / = str_replace ( '{'.$key.'}', $html, $form ); / / / Getting the webmasters for the owner property. Uses lists_funcs.php / $owner_select = webmasters_select($this->owner,null,1); / $form = str_replace('{owner}',$owner_select,$form); / / = "SELECT id, title FROM ".TBL_PREFIX."consoles WHERE deleted='0' AND site='".$this->id."'"; / = $conn->GetAll ( $sql ); / / = ""; / / ( $get as $record ) { / = $record[id]; / = $record[title]; / = ""; / ( $id == $this->default_console ) $selected = "selected"; / / .= "\n"; / / / $form = str_replace('{default_console}',$default_console,$form); / $form = str_replace('{ID}',"",$form); / as $key => $value) / = str_replace('{'.$key.'}', $this->$key, $form); / $form; } public function toString($delimiter = "\n") { $asArray = get_object_vars($this); foreach ($asArray as $key=>$val) $str.="$key = $val".$delimiter; return $str; } public function isMaster() { return ($this->id == $this->master_site); } public function getPayRates() { global $conn; include_once (CLASSES_PATH."rates.class.php"); $rates = new Rates($this->id,100000); return get_object_vars($rates); } public function getNewPayRates() { global $conn, $ADODB_FETCH_MODE; include_once (CLASSES_PATH."rates.class.php"); $rates = new Rates($this->id,100000); $rates->readNew(); return get_object_vars($rates); } public function updatePayRates($new_rates) { global $conn,$ADODB_FETCH_MODE; include_once (CLASSES_PATH."rates.class.php"); $query = "SELECT webmaster from ".TBL_PREFIX."config where wm_common=1 and siteid=".$this->id; $result = $conn->GetAll($query); foreach ($result as $row) { $row = array_change_key_case($row,CASE_LOWER); $webmaster = $row['webmaster']; $rates = new Rates($this->id,$webmaster); $new_rates['common'] = 0; $rates->update($new_rates); } } public function setPayRates($master_site=0) { global $conn,$ADODB_FETCH_MODE; include_once (CLASSES_PATH."rates.class.php"); $query = "SELECT webmaster from ".TBL_PREFIX."config where siteid=$master_site"; $result = $conn->GetAll($query); foreach ($result as $row) { $row = array_change_key_case($row,CASE_LOWER); $webmaster = $row['webmaster']; $rates = new Rates($master_site,$webmaster); $rates->siteid = $this->id; $rates->createCurrent(get_object_vars($rates)); } /* $query = "SELECT webmaster from ".TBL_PREFIX."config_new where siteid=$master_site"; $result = $conn->GetAll($query); foreach ($result as $row) { $row = array_change_key_case($row,CASE_LOWER); $webmaster = $row[webmaster]; $rates = new Rates($master_site,$webmaster); $rates->readNew($master_site,$webmaster); $rates->siteid = $this->id; $rates->createNew(get_object_vars($rates)); } */ } public function payRatesForm() { global $conn,$ADODB_FETCH_MODE; include_once (CLASSES_PATH."rates.class.php"); $rates = new Rates($this->id, 100000); $form = $rates->Form(); / = str_replace("{misc}","\n\n\n",$form); / $form; } public function redirect_welcome($username='',$password='',$email='',$subscription_id='',$recur_days='') { $glue = (stristr($this->welcome, '?'))?'&':"?"; echo ""; } public function redirect_deny($member_id) { echo ""; } public function global_change($sites, $action) { foreach($sites as $id) { $site = new Site($id); if($action == "activate") { $site->active = 1; $site->visible = 1;} if($action == "deactivate") { $site->active = 0; $site->visible = 0;} if($action == "active_only") { $site->active = 1; } if($action == "invisible_only") { $site->visible = 0; } if($action == "delete") { $site->active = 0; $site->visible = 0; $site->deleted = 1; } $site->save(); unset($site); } } public function get_tours($site, $def_value = null) { global $conn; $def = ($def_value != null && $def_value!=' - ')?$def_value:'Default tour'; if(!$this->tours[$site]) { $this->tours[$site][0] = $def; $query = "SELECT id, title from ".TBL_PREFIX."tours where site='$site' and deleted='0' and active='1' and visible='1'"; $result = $conn->GetAll($query); foreach($result as $row) { $id = $row[id]; $title = $row[title]; $this->tours[$site][$id] = $title; } } return $this->tours[$site]; } public function CascadingOrderForm() { global $conn; include_once (CLASSES_PATH."cascading_order.class.php"); $c_order = new CascadingOrder(0,$this->id); / = implode('',file(INNER_TEMPLATES_PATH."cascading_order.html")); / = str_replace('{cascading_order}',$c_order->order_select(),$form); / = str_replace('{geo_cascading_order}',$c_order->geo_order_select(),$form); / = str_replace('{misc}',"id>",$form); / "
Site $this->id: $this->title\n

"; / $form; / node global $doc; $make_xml = new Make_Xml($doc, 'data'); $node = $make_xml->addRow($make_xml->ext_node, 'cascading_order'); $make_xml->addValue($node, 1); $node = $make_xml->addRow($make_xml->ext_node, 'order_select'); $make_xml->addValue($node, $c_order->order_select()); $node = $make_xml->addRow($make_xml->ext_node, 'site_title'); $make_xml->addValue($node, $this->title); $node = $make_xml->addRow($make_xml->ext_node, 'siteID'); $make_xml->addValue($node, $this->id); $node = $make_xml->addRow($make_xml->ext_node, 'geo_order_select'); $make_xml->addValue($node, $c_order->geo_order_select()); $node = $make_xml->addRow($make_xml->ext_node, 'action_description'); $make_xml->addValue($node, 'cascading order'); } public function updateCascadingOrder($order) { global $conn; require_once(CLASSES_PATH."cascading_order.class.php"); $co = array(); $gco = array(); $alt_co = array(); $alt_gco = array(); foreach ($_POST as $key=>$value) { if (!preg_match("/.*order_\d+.*$/", $key)) continue; $alt = preg_replace("/.*order_(\d+).*$/", "$1", $key); $processor = preg_replace("/.*order_\d+_(.*)$/", "$1", $key); /* $co = explode('|','|'.$_POST['order_'.$alt]); unset($co[0]); $gco = explode('|','|'.$_POST['geo_order_'.$alt]); unset($gco[0]); */ if ($alt) { if (preg_match("/geo_order/", $key))$alt_gco[$processor] = $value; else $alt_co[$processor] = $value; } else { if (preg_match("/geo_order/", $key))$gco[$processor] = $value; else $co[$processor] = $value; } } $c_order = new CascadingOrder(0,$this->id); $c_order->update( array( 'order'=>$co, 'geo_order'=>$gco ) ); if (count($alt_co)>0) { / the alt_cascading $c_order = new CascadingOrder(0,$this->id,1); $c_order->update( array( 'order'=>$co, 'geo_order'=>$gco ) ); } } public function resetCascadingOrder() { global $conn; require_once(CLASSES_PATH."cascading_order.class.php"); $c_order = new CascadingOrder(0,$this->id); $c_order->clear(); / the alt cascading $c_order = new CascadingOrder(0,$this->id,1); $c_order->clear(); } /** * Sends postback in case a member has cancelled to the site postback url * * object $transaction * object $member * boolean */ public function send_postback(&$transaction, &$member) { global $conn; require_once(FUNCTIONS_PATH."http_post.php"); / there is no postback_url script set, act as if it's all ok if ($this->postback_url=='') return 1; foreach ($_GET as $key=>$value) $post .= "$key=$value&"; foreach ($_POST as $key=>$value) $post .= "$key=$value&"; if (is_object($transaction))foreach (get_object_vars($transaction) as $key=>$value) $post .= "transaction_$key=$value&"; if (is_object($member))foreach (get_object_vars($member) as $key=>$value) $post .= "member_$key=$value&"; $command = "$post"; if ($conn->debug) $conn->outp($command."\n"); $res = http_post($this->postback_url,$command); if ($res!='') return 1; else return 0; } } ?>id=$id; $this->read(); } return 1; } function read() { / Reads the info from the database and sets the properties, if no id reads for the current $this->id global $conn, $ADODB_FETCH_MODE; if (DB_IS_DOWN === true) { $objTour = FileStorage::getTourObject($this->id); if (!is_null($objTour)) { $objVars = get_object_vars($objTour); foreach($objVars as $key => $value) { $this->$key = $value; } } } else { $query = "SELECT * from ".TBL_PREFIX."tours where id=".$this->id; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $result = $conn->GetAll($query); $row = $result[0]; foreach ($row as $property_name=>$value) { $this->$property_name = $value; } } } function save() { / Saves into the database global $conn; $sql = "SELECT * FROM ".TBL_PREFIX."tours WHERE id = ".$this->id; $result = $conn->Execute($sql); $updateSQL = $conn->GetUpdateSQL($result, get_object_vars($this)); if ($updateSQL) $conn->Execute($updateSQL); / tours data to a php file FileStorage::storeToursData(); } function update($properties,$save_it=1) { foreach($properties as $property=>$value) { if ($this->$property != $value) { $this->$property = $value; } } if ($save_it) $this->save(); } function create($properties) { global $conn; foreach ($properties as $property_name=>$value) { $this->$property_name = $value; } $sql = "SELECT * FROM ".TBL_PREFIX."tours WHERE id = -1"; $result = $conn->Execute($sql); if ($conn->no_autoincrement) $this->id = $conn->GenID("seq_".TBL_PREFIX."tours",1); $this->deleted = 0; $insertSQL = $conn->GetInsertSQL($result, get_object_vars($this)); $conn->Execute($insertSQL); if (! $this->id) {$this->id = $conn->Insert_ID();} } function printForm() { global $conn; require_once(FUNCTIONS_PATH.'lists_funcs.php'); $form = implode('',file(INNER_TEMPLATES_PATH."tours.html")); $text_fields = array('id','title','url','site', 'wb_package_group', 'wb_package_id'); foreach($text_fields as $field) $form = str_replace('{'.$field.'}',$this->$field,$form); if ($this->active) $active_select = "\n\n"; else $active_select = "\n\n"; $form = str_replace('{active}',$active_select,$form); $form = str_replace('{price_model_select}',price_model_select($this->price_model),$form); if ($this->visible) $visible_select = "\n\n"; else $visible_select = "\n\n"; $form = str_replace('{visible}',$visible_select,$form); if ($this->id) $form = str_replace('{action}','update',$form); else $form = str_replace('{action}','create',$form); echo "$form"; } function toString($delimiter = "\n") { $asArray = get_object_vars($this); foreach ($asArray as $key=>$val) $str.="$key = $val".$delimiter; return $str; } function global_change($tours, $action) { foreach($tours as $id) { $tour = new Tour($id); if($action == "activate") { $tour->active = 1; $tour->visible = 1;} if($action == "deactivate") { $tour->active = 0; $tour->visible = 0;} if($action == "active_only") { $tour->active = 1; } if($action == "invisible_only") { $tour->visible = 0; } if($action == "delete") { $tour->active = 0; $tour->visible = 0; $tour->deleted = 1; } $tour->save(); unset($tour); } } } ?>'This username is already taken. Please try another one.'); public $twotier_percent = '-1.00'; public $is_aff_rep = 0; public $xml_container; public $reason_deny=''; public function Webmaster($id = null, $key='id') { global $conn, $ADODB_FETCH_MODE, $minpayoutsteps; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $this->table = TBL_PREFIX."webmasters"; $sql = "SELECT * FROM $this->table WHERE id = -1"; $result = $conn->Execute($sql); $obj_vars = $result->FetchObj(); if (array_key_exists($key, $obj_vars)) { $query = "SELECT * from $this->table where $key='$id'"; $result = $conn->GetAll($query); if (! is_array($result[0])) return 0; $row = $result[0]; foreach ($row as $property_name=>$value) { $this->$property_name = $value; } $this->password = encordec($this->password); $this->email = encordec($this->email); } $sql = "select points from ".TBL_PREFIX."rewards_points where `webmaster`='$this->id'"; $this->points = $conn->GetOne($sql); if($this->points != '') $this->wm_points_exist = true; $query = "SELECT distinct(master_site) AS id FROM ".TBL_PREFIX."sites WHERE owner='$this->id'"; $result = $conn->GetAll($query); foreach($result as $row) $this->owner_sites .= $row['id'].","; $this->owner_sites = ($this->owner_sites,0,-1); $this->gl_key = md5(serialize($this).PROGRAM_URL.$_SERVER["REMOTE_ADDR"].PROGRAM_PATH.date("Y-m-d H")); if(isset($_SESSION['lang'])) { if (is_file(XMLS_PATH.'lang/'.$_SESSION['lang'].'/container.xml')) { $this->xml_container = simplexml_load_file(XMLS_PATH.'lang/'.$_SESSION['lang']."/container.xml"); } else { $this->xml_container = simplexml_load_file(XMLS_PATH."lang/en/container.xml"); } } else { $this->xml_container = simplexml_load_file(XMLS_PATH."lang/en/container.xml"); } if (strlen($minpayoutsteps)>10) { $this->minpay_array=explode(',',$minpayoutsteps); } return 1; } public function read() { return $this->Webmaster($this->id, 'id'); } public function read_username($username) { if (!$username) return 0; return $this->Webmaster($username, 'username'); } public function save() { global $conn; $sql = "SELECT * FROM $this->table WHERE id = ".$this->id; $result = $conn->Execute($sql); $obj_vars = $result->FetchObj(); foreach($obj_vars as $var=>$val) if (! isset($this->$var)) $this->$var = ''; $this->password = encdec($this->password); $this->email = encdec($this->email); $updateSQL = $conn->GetUpdateSQL($result, get_object_vars($this), true); if ($updateSQL) $conn->Execute($updateSQL); $this->password = encordec($this->password); $this->email = encordec($this->email); } public function update_wm_points() { global $conn; $sql = "UPDATE `".TBL_PREFIX."rewards_points` SET `points`= '$this->points' WHERE `webmaster`='$this->id'"; $conn->Execute($sql); return 1; } public function create_wm_points() { global $conn; $sql = "INSERT INTO `".TBL_PREFIX."rewards_points` (`webmaster`, `points`) VALUES('$this->id', '$this->points')"; $conn->Execute($sql); $this->wm_points_exist = true; return 1; } public function update($properties,$save_it=1) { global $conn; unset($properties['id']); $ret = array(); $sql = "SELECT COUNT(*) FROM $this->table WHERE username='$properties[username]'"; $username_used = $conn->GetOne($sql); if ((int)$username_used>0) { unset($properties['username']); $ret[] = -2; } $this->verify_payment_info($properties); $columns = $conn->MetaColumns($this->table); foreach($columns as $column) if ($column->type=='timestamp')$this->{$column->name} = ''; foreach($properties as $property=>$value) { if ($property == 'allowed_products') { if (in_array(strval(0), $value)) { foreach ($value as $k=>$v) { if ($k!='0') $allowed_products_arr[]=$v; } $value = $allowed_products_arr; } } if (is_array($value)) $value = implode(",", $value); if ($this->$property != $value) { $this->$property = $value; } } if ($save_it) { $this->save(); if($this->wm_points_exist) $this->update_wm_points(); elseif($this->points != '') $this->create_wm_points(); $this->registerIPayoutEmail(); } return $ret; } public function create($properties) { global $conn,$auto_approve; / date_registered to the passed $_POST variables $properties ["date_registered"] = date("Y-m-d"); $this->approved = $auto_approve; $sql = "SELECT * FROM $this->table WHERE id = -1"; $result = $conn->Execute($sql); $obj_vars = $result->FetchObj(); foreach($obj_vars as $var=>$val) if (! isset($this->$var)) $this->$var = ''; if ($conn->no_autoincrement) $this->id = $conn->GenID("seq_".$this->table,100001); $insertSQL = $conn->GetInsertSQL($result, get_object_vars($this)); $conn->Execute($insertSQL); if (! $this->id) {$this->id = $conn->Insert_ID();} $this->update($properties); />setPayRates(); } public function printForm($new=1) { global $conn; require_once(FUNCTIONS_PATH."lists_funcs.php"); if ($new) $form = implode('',file(self::fixLangTemplate("new_webmaster.html"))); $form = implode('',file(self::fixLangTemplate("update_webmaster.html"))); $asArray = get_object_vars($this); foreach($asArray as $field=>$value) $form = str_replace('{'.$field.'}',$this->$field,$form); $form = str_replace('{ID}',"",$form); if ($this->active) $form = str_replace('{active_select}',"\n\n",$form); else $form = str_replace('{active_select}',"\n\n",$form); if ($new) $form = str_replace('{submit}',"",$form); else $form = str_replace('{submit}',"",$form); echo "$form"; } public function verify_payment_info($properties) { $email = ''; foreach ($this->monitored_fields as $key) { if($key == 'email' or $key == 'password') $key = encordec($key); if (isset($properties[$key]) && $this->$key!=$properties[$key]) $email .="$key field changed from '".$this->$key."' to '".$properties[$key]."'
\n"; $this->{"old_".$key} = $this->$key; $this->{"new_".$key} = $properties[$key]; } if ($email!='' && $this->ch_details) { $this->message = $email; $this->subject = 'Payment Details Change'; $this->send_email($this->ch_details_email_template); } } /** * headers can be set at the top of the template like this: * {header} * Subject: Welcome to program_name.com! * Return-Path: * From: "Program Name.com" <> * {/header} * * string $email_html * string */ public function parse_headers($email_html) { preg_match_all("/{(header)}([\s\S.]*){\/(header)}/", $email_html, $arr_header); preg_match_all("/([^:]*):(.*)/",$arr_header[2][0], $arr_mail_headers); foreach ($arr_mail_headers[1] as $key=>$value) $this->mailHeaders[trim($value)] = trim($arr_mail_headers[2][$key]); return str_replace($arr_header[0][0], '', $email_html); } /** * Sends email to the webmster. It gets the webmaster parameters, and replaces the tags named as the parameters. * For example {id} tag will be replaced by the $webmaster->id parameter * * string $template * boolean $instant */ public function send_email($template, $instant = 0) { global $program_name; require_once(CLASSES_PATH."mail_to_db.class.php"); (CONFIG_PATH."payout_config.php"); $email_html = ("", (OUTER_TEMPLATES_PATH.$template)); $asArray = get_object_vars($this); foreach($asArray as $field=>$value) $email_html = str_replace('{'.$field.'}', $this->$field, $email_html); $this->subject = "$this->subject for $program_name"; $email_html = $this->parse_headers($email_html); if ($this->mailHeaders['From']=='' && $this->mailHeaders['from']=='') $this->mailHeaders['From'] = "\"".PROGRAM_NAME."\" <$webmasters_support_email>"; if ($this->mailHeaders['Subject']!='' || $this->mailHeaders['subject']!='') $this->subject = $this->mailHeaders['Subject'].$this->mailHeaders['subject']; foreach ($this->mailHeaders as $key=>$value) if (!preg_match("/subject|from$/i", $key)) $mailHeader .="$key: $value\n"; $mailHeader = "From: ".$this->mailHeaders['From'].$this->mailHeaders['from']."\n".$mailHeader; $to = "\"$this->fname $this->lname\" <$this->email>"; / ($this->mailHeaders['From'].$this->mailHeaders['from']!='') $to=''; / what is this for? i see no logic in this - i had problems in ticket 8394 / "Changed payment info Notifications" and "Brute Force Notifications" were not working because of this if ($instant) { mail($to, $this->subject, $email_html,"$mailHeader"."Content-type: text/html; charset=iso-8859-1"); } else { $mail = new MailDB($to, $this->subject,$email_html,"$mailHeader"."X-Priority: 1",time()); } } /** * Sends confirmation email to the webmster, and adds "confirm_link" as class property, * which will be later replace the {confirm_link} tag in the conmfirmation template. * The method also defines the email subject accordingly. * */ public function send_confirmation_email() { $hash = md5($this->id.$this->username.$this->password.$this->email.$this->fname.$this->lname); $this->confirm_link = PROGRAM_URL.'/wmreg/confirm.php?w='.$this->id.'&hash='.$hash; $this->subject = 'Confirmation email'; $this->send_email($this->wm_join_confirmation_mail_template, 1); } public function verify_registration($array) { global $conn; foreach($array as $public => $value) { $this->$public = $value; $$public = $value; $len = $public.'_len'; $$len = ($value); } $reg_errors = ''; if(isset($_SESSION['lang'])) { if (is_file(XMLS_PATH.'lang/'.$_SESSION['lang'].'/container.xml')) { $this->_xml_container = simplexml_load_file(XMLS_PATH.'lang/'.$_SESSION['lang']."/container.xml"); } else { $this->_xml_container = simplexml_load_file(XMLS_PATH."lang/en/container.xml"); } } else { $this->_xml_container = simplexml_load_file(XMLS_PATH."lang/en/container.xml"); } ## Company name check if($company_len < 3) { $this->company = ''; $reg_errors .= $this->_xml_container->errors->company_name_short."
\n"; } ## Website URL check if(!preg_match("/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/*/i", $this->website)) { $this->website = ''; $reg_errors .= $this->_xml_container->errors->incorrect_url."
\n"; } ## Email check if(!eregi("^[_\.0-9a-z-]+([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$", $email)) { $this->email = ''; $reg_errors .= $this->_xml_container->errors->incorrect_email."
\n"; } ## First name check if(!preg_match("/^.{2,}$/", $fname)) { $this->fname = ''; $reg_errors .= $this->_xml_container->errors->invalid_fname."
\n"; } ## Last name check if(!preg_match("/^.{2,}$/", $lname)) { $this->lname = ''; $reg_errors .= $this->_xml_container->errors->invalid_lname."
\n"; } ## Phone number check if($phone_len < 3) { $this->phone = ''; $reg_errors .= $this->_xml_container->errors->invalid_phone."
\n"; } ## icq check if(strlen($icq) && !preg_match("/^\d*$/", $icq)) { $this->icq = ''; $reg_errors .= $this->_xml_container->errors->invalid_icq."
\n"; } ## Beneficiary check if($payto_len < 3) { $this->payto = ''; $reg_errors .= $this->_xml_container->errors->invalid_beneficiary.".
\n"; } ## Addreess check if($address_len < 3) { $this->address = ''; $reg_errors .= $this->_xml_container->errors->incorrect_address."
\n"; } ## City check if($city_len < 3) { $this->city = ''; $reg_errors .= $this->_xml_container->errors->incorrect_city."
\n"; } if($country == 'US') { if(!eregi("^[A-Z]{2}$", $state)) $reg_errors .= $this->_xml_container->errors->select_state."
\n"; if(!eregi("^[0-9]{5}$", $zip)) { $this->zip = ''; $reg_errors .= "Invalid ZIP code.
\n"; } if($taxid_len < 9) $reg_errors .= $this->_xml_container->errors->invalid_taxid."
\n"; } else { if($zip_len < 2) { $this->zip = ''; $reg_errors .= $this->_xml_container->errors->invalid_zip."
\n"; } } $payment_methods = array('paxum', 'cheque', 'ipayout', 'epassporte', 'wire', 'paypal', 'revupcard'); ## Check payment method if(!in_array(strtolower($payment_method), $payment_methods)) $reg_errors .= $this->_xml_container->errors->select_payment_method."
\n"; ## Check i-Payout if(preg_match("/ipayout/i",$payment_method) && !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $wm_ipayout_email)) { $this->wm_ipayout_email = ''; $reg_errors .= $this->_xml_container->errors->invalid_ipayout."
\n"; } ## Check Paxum if(preg_match("/paxum/i",$payment_method) && !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $wm_paxum_email)) { $this->wm_paxum_email = ''; $reg_errors .= $this->_xml_container->errors->invalid_paxum."
\n"; } ## Check ePassporte if(preg_match("/Epassporte/i",$payment_method) && !eregi("^[_\.0-9a-z-]+(\.com)$", $wm_epassporte_email)) { $this->wm_epassporte_email = ''; $reg_errors .= $this->_xml_container->errors->invalid_epassporte."
\n"; } ## Check RevUpCard if(preg_match("/revupcard/i",$payment_method) && strlen($revupcardid)<15) { $this->revupcardid = ''; $reg_errors .= $this->_xml_container->errors->invalid_revup."
\n"; } ## Check Wire if(preg_match("/Wire/i",$payment_method)) { if(!eregi("^[0-9]{1,}$", $wire_account_number)) { $this->wire_account_number = ''; $reg_errors .= $this->_xml_container->errors->invalid_account_number."
\n"; } /* if($wire_swift_len < 3) { $this->wire_swift = ''; $reg_errors .= "Invalid SWIFT code.
\n"; } if($wire_aba_len < 3) { $this->wire_aba = ''; $reg_errors .= "Invalid ABA code.
\n"; }*/ if($wire_bank_name_len < 3) { $this->wire_bank_name = ''; $reg_errors .= $this->_xml_container->errors->invalid_bank_name."
\n"; } if($wire_bank_city_len < 3) { $this->wire_bank_city = ''; $reg_errors .= $this->_xml_container->errors->invalid_bank_city."
\n"; } if($wire_bank_country_len < 3) { $this->wire_bank_country = ''; $reg_errors .= $this->_xml_container->errors->invalid_bank_country."
\n"; } } if ($day!='' && $month!='' && $year!='') { $this->datebirth = date("Y-m-d", strtotime("$year-$month-$day")); if (strtotime("$year-$month-$day")>strtotime("-18 year")) { $reg_errors .= $this->_xml_container->errors->invalid_birthdate."
\n"; } } if($minpay+0 < 50) $reg_erros .= $this->_xml_container->errors->invalid_amount."
\n"; ## Username check $sql = "SELECT COUNT(*) FROM $this->table WHERE username='$username'"; $username_used = $conn->GetOne($sql); if($username_used+0 > 0) { $this->username = ''; $reg_errors .= $this->_xml_container->errors->username_used."
\n"; } elseif($username_len < 4 || $username_len > 12) { $this->username = ''; $reg_errors .= $this->_xml_container->errors->username_lenght."
\n"; } ## Password check if($password_len < 6 || $password_len > 12) { $this->password = ''; $this->password2 = ''; $reg_errors .= $this->_xml_container->errors->password_lenght."
\n"; ## Password match } elseif ($password != $password2) { $this->password = ''; $this->password2 = ''; $reg_errors .= $this->_xml_container->errors->passwords_match."
\n"; } if($reg_errors == '') { $this->data_correct = true; } else { $this->reg_errors = $reg_errors; } } public function fix_address() { require_once(CLASSES_PATH."state.class.php"); require_once(CLASSES_PATH."country.class.php"); $country = new Country($this->country,'iso_2'); $state = new State($this->state); $this->update(array('full_country' => $country->name, 'full_state' => $state->name, 'name' => "$this->fname $this->lname")); unset($country); unset($state); } /** * Register i-Payout email * */ public function registerIPayoutEmail() { global $conn; if ($this->payment_method != 'ipayout' OR !$this->wm_ipayout_email OR $this->wm_ipayout_email == $this->wm_ipayout_registered) { return false; } require_once(CLASSES_PATH . 'ipayout.class.php'); $iPayout = new IPayout(); $result = $iPayout->registerWebmaster($this); if ($result) { $this->wm_ipayout_registered = $this->wm_ipayout_email; $this->save(); } } public function adminForm($by_admin='1') { global $conn, $fraud_fields; require_once(FUNCTIONS_PATH."lists_funcs.php"); $form = ('',(self::fixLangTemplate($this->form_template_file))); $payment_history_template = ("", (self::fixLangTemplate($this->payment_history_template_file))); $this->countries_select = wm_countries_select($this->country, ''); $this->states_select = states_select($this->state); if (!in_array($this->minpay, $this->minpay_array)) $this->minpay_array[] = $this->minpay; $this->minpay_select = minpay_select($this->minpay, $this->minpay_array); (!empty($this->xml_container->masscontainer->yes))?$yes = $this->xml_container->masscontainer->yes : $yes = 'Yes'; (!empty($this->xml_container->masscontainer->no))?$no = $this->xml_container->masscontainer->no : $no = 'No'; (!empty($this->xml_container->masscontainer->none))?$none = $this->xml_container->masscontainer->none : $none = 'None'; $this->massmail_select = custom_select(array(1=>$yes, 0=>$no), $this->massmail, null); $this->signup_mails_select = custom_select(array(1=>$yes, 0=>$no), $this->signup_mails, null); $this->ch_details_select = custom_select(array(1=>$yes, 0=>$no), $this->ch_details, null); $this->brute_force_select = custom_select(array(1=>$yes, 0=>$no), $this->brute_force, null); $this->webmaster_id = $this->id; $this->password = encordec($this->password); $this->email = encordec($this->email); / global $doc; $make_xml = new Make_Xml($doc, 'data'); $asArray = get_object_vars($this); foreach($asArray as $field=>$value) { if (is_array($this->$field)) continue; $node = $make_xml->addRow($make_xml->ext_node, $field); $make_xml->addValue($node, $this->$field); } / the payment history $titles = array('th_collected_since','th_payout_period', 'th_payout'); $widths = array(80,180,''); $alignment = array('left','left','left'); $totals = array(); $sql = "select * from `". TBL_PREFIX ."payout` where webmaster='$this->id' order by end_date"; $res = $conn->GetAll($sql); / hide payout for last period (#8698) $q = "SELECT start_date, end_date, processed FROM ".$tbl_prefix."payout_dates where end_dateSelectLimit($q, 1); $hide_start = $hide_date->fields[start_date]; $hide_end = $hide_date->fields[end_date]; foreach ($res as $row) { / hide payout for last period (#8698) if($row['start_date']==$hide_start || $row['end_date']==$hide_end) continue; $sql = "select ADDDATE(max(end_date), INTERVAL 1 DAY) from ". TBL_PREFIX ."payout where webmaster='$this->id' and start_date<'$row[start_date]'"; $sql_trn = "select min(trn_date) from ". TBL_PREFIX ."transactions where webmaster='$this->id' and trn_date>'0000-00-00'"; $table_row = array(); $first_date = $conn->GetOne($sql); if (!$first_date) $first_date = $conn->GetOne($sql_trn); if (strtotime($first_date)>strtotime($row['start_date'])) $first_date = $row['start_date']; $table_row[] = $first_date; $prefix = ""; if ($by_admin) $prefix = ""; $suffix = ""; $table_row[] = $prefix.$row['start_date']." -- ".$row['end_date'].$suffix; $table_row[] = $row['payout']; if (array_key_exists("payment_method", $row)) { $table_row[] = ''.$row['payment_method']; $titles[3] = 'th_payment_method'; $widths[3] = 80; $alignment[3] = 'right'; $totals[3]=''; } if (array_key_exists("min_payout", $row)) { $table_row[] = ''.$row['min_payout']; $titles[4] = 'th_minimum_payout'; $widths[4] = 60; $alignment[4] = 'right'; $totals[4]=''; } $totals[0]=''; $totals[1]=''; $totals[2]+=0+$row['payout']; $table[] = $table_row; } ksort($totals); include_once(FUNCTIONS_PATH."tables_funcs.php"); $payment_history = build_xml_data($table,$widths,$alignment,$titles,$totals,'100%','wm_payment_history'); if ($payment_history=='') $payment_history = "No payments have been calculated yet."; if ($by_admin) { (!empty($this->xml_container->masscontainer->activate))?$activate = $this->xml_container->masscontainer->activate : $activate = 'Activate'; (!empty($this->xml_container->masscontainer->freeze))?$freeze = $this->xml_container->masscontainer->freeze : $freeze = 'Freeze'; if ($this->frozen) $this->freeze_activate = ''; else $this->freeze_activate = ''; $this->sites_select = sites_select(null,null,null,null,null,1); $form = str_replace('onSubmit="return validate(this)"','',$form); / Removes javascript form check $allowed_products_array = array(); $allowed_products_array = explode(",", $this->allowed_products); $q = "select t1.*, t2.id as siteId, t2.title as siteTitle from ". TBL_PREFIX ."products as t1 left join ". TBL_PREFIX ."sites as t2 on t1.site=t2.id where t1.active='1' and t1.deleted='0' order by t1.site, t1.id"; $res = $conn->GetAll($q); $products[0]=(!empty($this->xml_container->masscontainer->defaults))?$this->xml_container->masscontainer->defaults :'Defaults'; foreach ($res as $key=>$value) { $products[$value['id']] = $value['siteId']."-".$value['siteTitle']." / ".$value['id']."-".$value['title']; if ($value['visible']) $visible_products[] = $value['id']; } if (!(count($allowed_products_array)>0 && $allowed_products_array[0]!='')) $allowed_products_array['Defaults'] = '0'; $this->allowed_products_select = custom_checkbox_new($products, $allowed_products_array, "allowed_products"); $this->allowed_products_height = (count($products)>100)?"100":count($products)+1; $aff_reps = get_aff_reps(); foreach ($aff_reps as $key=>$value)$aff_reps[$key] = $key." - ".$value; $this->aff_rep_select = custom_select($aff_reps, $this->aff_rep, null, $none); $this->ma_select = webmasters_select($this->ma, null, $none); $this->consoles_select = custom_select(array(1=>$yes, 0=>$no), $this->consoles); / hiperlink to referred webmaster if ($this->ma > 0) { $form = str_replace('{ma}',''.$this->ma.'',$form); } else { $form = str_replace('{ma}','',$form); } $asArray = get_object_vars($this); $fraud_array = explode('|',$fraud_fields); foreach($fraud_array as $id=>$field) { $form = str_replace('{'.$field.'_wm_fraud}', 'wm_fraud', $form); $node = $make_xml->addRow($make_xml->ext_node, $field.'_wm_fraud'); $make_xml->addValue($node, 1); } foreach($asArray as $field=>$value) { / = str_replace('{'.$field.'}', $this->$field,$form); / = str_replace('{'.$field.'_wm_fraud}', '',$form); if (is_array($this->$field)) continue; $node = $make_xml->addRow($make_xml->ext_node, $field); $make_xml->addValue($node, $this->$field); if(!in_array($field, $fraud_array)) { $node = $make_xml->addRow($make_xml->ext_node, $field.'_wm_fraud'); $make_xml->addValue($node, ''); } } } /* else { $admin_tags = get_object_vars($this); foreach ($admin_tags as $tag=>$variable) { / = str_replace($tag,'',$form); $node = $make_xml->addRow($make_xml->ext_node, $tag); $make_xml->addValue($node, ''); } } */ /'{payment_history}',$payment_history,$form); / history $node = $make_xml->addRow($make_xml->ext_node, 'payment_history'); $make_xml->addValue($node, $payment_history); / the form $node = $make_xml->addRow($make_xml->ext_node, 'edit_webmaster'); $make_xml->addValue($node, 1); / $form; } public function rightsForm() { global $conn; include_once (CLASSES_PATH."wm_rights.class.php"); $rights = new wm_rights($this->id); $form = $rights->rightsForm(); return $form; } public function updateRights($wm_rights) { global $conn; include_once (CLASSES_PATH."wm_rights.class.php"); $rights = new wm_rights($this->id); $form = $rights->rightsForm(); $form = $rights->update($wm_rights); return $form; } public function toString($delimiter = "\n") { $asArray = get_object_vars($this); foreach ($asArray as $key=>$val) $str.="$key = $val".$delimiter; return $str; } /** * * Checks if the program is allowed for this webmaster and if not replaces it with the default one * * array */ public function getPrograms($site='all', $tour='all', $console=-1) { global $conn; if (!$site) $site='all'; if (!$tour) $tour='all'; $query = "SELECT * FROM ".TBL_PREFIX."programs WHERE bonus_program=0 AND visible=1 order by id"; $programs = $conn->GetAll($query); $allowed_programs = array(); $special_programs = array(); foreach ($programs as $program) { $is_good = 1; $current = $program; $current['webmaster'] = explode(',',$current['webmaster']); $current['site'] = explode(',', $current['site']); $current['tour'] = explode(',', $current['tour']); if (! is_array($current)) $is_good=0; / No such program in the database if (! in_array($this->id,$current['webmaster']) and ! in_array('all',$current['webmaster'])) $is_good=0; / Webmaster is not in the list and program not for everyone if (! in_array($site,$current['site']) and ! in_array('all',$current['site'])) $is_good=0; / Site not in the program and program not for all sites if (! in_array($tour,$current['tour']) and ! in_array('all',$current['tour'])) $is_good=0; / Tour not in the program and program not for all tours / ($current['consoles']>=0 and (($current['consoles']==0 and $console>0) || ($current['consoles']==1 and $console==0))) $is_good=0; / There is special console conditions that does not match the link code if ($current['replace_with']) $is_good=0; / Program deactivated and replaced if ($is_good) { $allowed_programs[$program['id']]=$program; / all previous checks - check whether this webmaster has special program assigned and hide other programs if(in_array($this->id,$current['webmaster'])) $special_programs[$program['id']]=$program; } } if(is_array($special_programs) && sizeof($special_programs)>=1) $allowed_programs = $special_programs; return $allowed_programs; } public function validateProgram($program, $site='all', $tour='all', $console=-1, $trn_date='CURRENT_DATE') { global $conn, $default_program; $old_mode = $conn->fetchMode; $conn->fetchMode = 2; />aff_rep_table is defined in transaction.class.php in method get_config() $prefix = ""; if($this->aff_rep_table) $prefix = "aff_rep_"; /* Checking for a bonus program available for this combination of input parameters */ if ($trn_date!='CURRENT_DATE') $trn_date = "'".$trn_date."'"; $query = "SELECT * from ".TBL_PREFIX.$prefix."programs WHERE bonus_program=1 and $trn_date between start_date and end_date ORDER BY id"; $bonus_programs = $conn->GetAssoc($query); if (is_array($bonus_programs) and count($bonus_programs)>0) { foreach ($bonus_programs as $bprogram=>$properties) { if ($properties['replace_program']>0 and $properties['replace_program']!=$program) continue; $bonus_program = $properties; $bonus_program['id'] = $bprogram; $bonus_program['webmaster'] = explode(',',$properties['webmaster']); $bonus_program['site'] = explode(',',$properties['site']); $bonus_program['tour'] = explode(',',$properties['tour']); if (! in_array($this->id,$bonus_program['webmaster']) and ! in_array('all',$bonus_program['webmaster'])) continue; / Webmaster is not in the list and program not for everyone if (! in_array($site,$bonus_program['site']) and ! in_array('all',$bonus_program[site])) continue; / Site not in the program and program not for all sites if (! in_array($tour,$bonus_program['tour']) and ! in_array('all',$bonus_program[tour])) continue; / Tour not in the program and program not for all tours / ($bonus_program['consoles']>=0 and (($bonus_program['consoles']==0 and $console>0) || ($bonus_program['consoles']==1 and $console==0))) continue; / There is special console conditions that does not match the link code $conn->fetchMode = $old_mode; $program = $bonus_program['id']; return $program; / Bonus program is returned } } /* End of bonus program checking */ $query = "SELECT * FROM ".TBL_PREFIX.$prefix."programs WHERE bonus_program=0 order by id"; $programs = $conn->GetAssoc($query); $conn->fetchMode = $old_mode; if ($programs[$program]['replace_with']>0) $program = $programs[$program]['replace_with']; / If a program is disabled and replaced the new one will be used $current = $programs[$program]; $current['webmaster'] = explode(',',$current['webmaster']); $current['site'] = explode(',', $current['site']); $current['tour'] = explode(',', $current['tour']); if (! is_array($current)) return $default_program; / No such program in the database if (! in_array($this->id,$current[webmaster]) and ! in_array('all',$current['webmaster'])) return $default_program; / Webmaster is not in the list and program not for everyone if (! in_array($site,$current['site']) and ! in_array('all',$current['site'])) return $default_program; / Site not in the program and program not for all sites if (! in_array($tour,$current['tour']) and ! in_array('all',$current['tour'])) return $default_program; / Tour not in the program and program not for all tours / ($current['consoles']>=0 and (($current['consoles']==0 and $console>0) || ($current['consoles']==1 and $console==0))) return $default_program; / There is special console conditions that does not match the link code if ($current['replace_with']) return $current['replace_with']; / Program deactivated and replaced return $program; / Program is good } public function getRates($program, $site='all', $tour='all', $console=-1, $original_program, $product, $trn_date='CURRENT_DATE') { global $conn, $twotier_percent; if (! $product or ! $program) return array(); $old_mode = $conn->fetchMode; $conn->fetchMode = 2; />aff_rep_table is defined in transaction.class.php in method get_config() $prefix = ""; if($this->aff_rep_table) { $prefix = "aff_rep_"; / the proper program id from the mpa3_aff_rep_programs, ad it may differ from the sale's program id, which is valid for mpa3_programs table only $sql = "SELECT id from ".TBL_PREFIX.$prefix."programs WHERE bonus_program=1 and CURRENT_DATE between start_date and end_date ORDER BY id"; $program = $conn->GetOne($sql); if (!$program) { $sql = "select id from ".TBL_PREFIX.$prefix."programs where webmaster='$this->id' and site='$site' and tour='$tour'"; $program = $conn->GetOne($sql); } if (!$program) { $sql = "select id from ".TBL_PREFIX.$prefix."programs where webmaster='$this->id' and site='$site' and tour='all'"; $program = $conn->GetOne($sql); } if (!$program) { $sql = "select id from ".TBL_PREFIX.$prefix."programs where webmaster='$this->id' and site='all' and tour='all'"; $program = $conn->GetOne($sql); } if (!$program) { $sql = "select id from ".TBL_PREFIX.$prefix."programs where site='$site' and tour='$tour' and webmaster='all'"; $program = $conn->GetOne($sql); } if (!$program) { $sql = "select id from ".TBL_PREFIX.$prefix."programs where site='$site' and tour='all' and webmaster='all'"; $program = $conn->GetOne($sql); } if (!$program) { $sql = "select id from ".TBL_PREFIX.$prefix."programs where site='all' and webmaster='all' and tour='all'"; $program = $conn->GetOne($sql); } $original_program = $program; } / We should validate the program again in case of cheating or in case bonus program was assogned and expired at the time of sign up / or When the sign up appened we have a bonus program active if ($original_program!=$program and $original_program>0) $program = $this->validateProgram($original_program, $site, $tour, $console, $trn_date); else $program = $this->validateProgram($program, $site, $tour, $console, $trn_date); / = unserialize($conn->GetOne("select products_programs from ".TBL_PREFIX."programs where id=$program")); $sql = "select * from ".TBL_PREFIX.$prefix."programs where id=$program"; $programs = $conn->GetRow($sql); $products_programs = unserialize(stripslashes($programs['products_programs'])); unset($programs['id']); unset($programs['title']); unset($programs['description']); unset($programs['webmaster']); unset($programs['site']); unset($programs['tour']); unset($programs['consoles']); unset($programs['insert_time']); if ($products_programs['all']>0) $product = 'all'; $rates = $conn->GetAll("SELECT * from ".TBL_PREFIX."basic_programs where id=".($products_programs[$product]+0)); if ($rates[0]['console_payrate']>0 && $console>0)$rates = $conn->GetAll("SELECT * from ".TBL_PREFIX."basic_programs where id=".$rates[0]['console_payrate']); $rates[0]['program'] = $program; $conn->fetchMode = $old_mode; $rate_2tier = $conn->GetOne("select twotier_percent from ".TBL_PREFIX."webmasters where id=".$this->ma); if ($rate_2tier < 0) $rate_2tier = $twotier_percent; $return_array = array_merge(array('rate_2tier' => $rate_2tier), $rates[0], $programs); $empty_array = array(); foreach ($return_array as $key=>$value) if ($key!='program') $empty_array[$key]=0; else $empty_array[$key]=$return_array[$key]; $empty_array['program'] = $return_array['program']; $empty_array['original_program'] = $return_array['original_program']; / if webmaster account is inhouse and if yes - set payout to 0 if($this->inhouse==1) { $empty_array['insert_time'] = date("Y-m-d H:i:s"); return $empty_array; } if (is_array($rates[0])) return $return_array; else return $empty_array; } public function getPayRates($site=0, $table='config') { global $conn; if ($table == 'config') { $query = "SELECT * from ". TBL_PREFIX ."config_bonus where bsdate<=now() and bedate>=now()"; $result = $conn->GetAll($query); $source = 'bonus'; } if (! is_array($result[0])) { $query = "SELECT * from ".TBL_PREFIX."$table where siteid=$site and webmaster=".$this->id; $result = $conn->GetAll($query); $source = 'site_webmaster_specific'; } if (! is_array($result[0])) { $query = "SELECT * from ".TBL_PREFIX."$table where siteid=0 and wm_common='0' and webmaster=".$this->id; $result = $conn->GetAll($query); $source = 'webmaster_global'; } if (! is_array($result[0])) { $query = "SELECT * from ".TBL_PREFIX."$table where siteid=$site and webmaster=100000"; $result = $conn->GetAll($query); $source = 'site_global'; } if (! is_array($result[0])) { $query = "SELECT * from ".TBL_PREFIX."$table where siteid=0 and webmaster=100000"; $result = $conn->GetAll($query); $source = 'global'; } $row = $result[0]; unset($row['webmaster']); $rates = array(); foreach($row as $key=>$val) $rates[$key] = $val; $rates['source'] = $source; return $rates; } public function getAffRepPayRates($site=0) { return $this->getPayRates($site, 'aff_rep_config'); } public function updatePayRates($rates, $site=0, $table='config') { global $conn; require_once(CLASSES_PATH."rates.class.php"); $rates['wm_common'] = 0; $wrates = new Rates($site,$this->id, $table); $wrates->update($rates,0); $wrates->fetchNumbersForSave(); $wrates->save(); if ($site==0) { $query = "select id from ".TBL_PREFIX."sites"; $result = $conn->GetAll($query); foreach ($result as $s) { $wrates->siteid = $s[id]; $wrates->save(); } } } public function updateAffRepPayRates($rates, $site=0) { $this->updatePayRates($rates, $site, 'aff_rep_config'); } public function setPayRates($table='config') { global $conn; $query = "SELECT * from ".TBL_PREFIX."$table where webmaster=100000"; $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $res = $conn->GetAll($query); foreach ($res as $row) { $rates = array(); $sql = "SELECT * FROM ".TBL_PREFIX."$table WHERE siteid=-1 and webmaster=0"; $result = $conn->Execute($sql); $row[webmaster] = $this->id; $insertSQL = $conn->GetInsertSQL($result, $row); $conn->Execute($insertSQL); } } public function setAffRepPayRates() { $this->setPayRates('aff_rep_config'); } public function clearPayRates($site, $table='config') { global $conn; include_once (CLASSES_PATH."rates.class.php"); $wrates = new Rates($site,$this->id, $table); return $wrates->del(); } public function clearAffRepPayRates($site) { global $conn; if ($site) $site_criteria = "and siteid='$site'"; $sql = "DELETE FROM ". TBL_PREFIX ."aff_rep_programs WHERE webmaster='$this->id' $site_criteria"; $conn->Execute($sql); return $conn->Affected_Rows(); } public function payRatesForm($site, $table='config') { global $conn; include_once (CLASSES_PATH."rates.class.php"); $rates = new Rates($site, $this->id, $table); / the payrates with the getPayRates method as this is the one that is used on signup, / is showing the actual rates that the signup will credit the webmaster with foreach ($this->getPayRates($site, $table) as $key => $value) $rates->$key = $value; $form = $rates->Form(); $misc = "\n\n\nid>"; / node global $doc; $make_xml = new Make_Xml($doc, 'data'); $node = $make_xml->addRow($make_xml->ext_node, 'edit_payrates'); $make_xml->addValue($node, 1); $node = $make_xml->addRow($make_xml->ext_node, 'misc'); $make_xml->addValue($node, $misc); } public function affRepPayRatesForm($site, $table='aff_rep_config') { global $conn; include_once (CLASSES_PATH."rates.class.php"); include_once (FUNCTIONS_PATH."lists_funcs.php"); $aff_rep_program_selector = ("", (self::fixLangTemplate("admin_aff_rep_program_selector.html"))); $programsArr = array ( '-1'=> ($this->xml_container->masscontainer->none)?$this->xml_container->masscontainer->none :"None", '0' => ($this->xml_container->masscontainer->per_unique)?$this->xml_container->masscontainer->per_unique :"Per Unique", '1' => ($this->xml_container->masscontainer->per_signup)?$this->xml_container->masscontainer->per_signup :"Per Signup", '2' => ($this->xml_container->masscontainer->partnership)?$this->xml_container->masscontainer->partnership :"Partnership", '3' => ($this->xml_container->masscontainer->per_activ_member)?$this->xml_container->masscontainer->per_activ_member :"Per Active Member" ); $rates = new Rates($site, $this->id, $table); / the payrates with the getPayRates method as this is the one that is used on signup, / is showing the actual rates that the signup will credit the webmaster with foreach ($this->getPayRates($site, $table) as $key => $value) $rates->$key = $value; $form = $rates->Form(); $aff_rep_program_selector = str_replace("{use_program_select}",custom_select($programsArr, $rates->use_program),$aff_rep_program_selector); $misc = $aff_rep_program_selector."\n\n\nid>"; / node global $doc; $make_xml = new Make_Xml($doc, 'data'); $node = $make_xml->addRow($make_xml->ext_node, 'aff_rates'); $make_xml->addValue($node, 1); $node = $make_xml->addRow($make_xml->ext_node, 'misc'); $make_xml->addValue($node, $misc); } public function XSellRatesForm() { global $conn; include_once (CLASSES_PATH."xsell_pay_rates.class.php"); $rates = new XSellPayRate($this->id); $rates->Form(); / node global $doc; $make_xml = new Make_Xml($doc, 'data'); $node = $make_xml->addRow($make_xml->ext_node, 'xsell_payrates'); $make_xml->addValue($node, 1); } public function updateXSellRates($ez_rates) { global $conn; require_once(CLASSES_PATH."xsell_pay_rates.class.php"); $rates = new XSellPayRate($this->id); $rates->update($ez_rates); } public function getXSellRates() { global $conn; require_once(CLASSES_PATH."xsell_pay_rates.class.php"); $rates = new XSellPayRate($this->id); return $rates; } public function CascadingOrderForm() { global $conn; include_once (CLASSES_PATH."cascading_order.class.php"); $c_order = new CascadingOrder($this->id); / node global $doc; $make_xml = new Make_Xml($doc, 'data'); $node = $make_xml->addRow($make_xml->ext_node, 'wm_cascading_order'); $make_xml->addValue($node, 1); $node = $make_xml->addRow($make_xml->ext_node, 'cascading_order'); $make_xml->addValue($node, $c_order->order_select()); $node = $make_xml->addRow($make_xml->ext_node, 'geo_cascading_order'); $make_xml->addValue($node, $c_order->geo_order_select()); $node = $make_xml->addRow($make_xml->ext_node, 'misc'); $make_xml->addValue($node, "id>"); } public function updateCascadingOrder($order) { global $conn; require_once(CLASSES_PATH."cascading_order.class.php"); $co = array(); $gco = array(); $alt_co = array(); $alt_gco = array(); foreach ($_POST as $key=>$value) { if (!preg_match("/.*order_\d+.*$/", $key)) continue; $alt = preg_replace("/.*order_(\d+).*$/", "$1", $key); $processor = preg_replace("/.*order_\d+_(.*)$/", "$1", $key); /* $co = explode('|','|'.$_POST['order_'.$alt]); unset($co[0]); $gco = explode('|','|'.$_POST['geo_order_'.$alt]); unset($gco[0]); */ if ($alt) { if (preg_match("/geo_order/", $key))$alt_gco[$processor] = $value; else $alt_co[$processor] = $value; } else { if (preg_match("/geo_order/", $key))$gco[$processor] = $value; else $co[$processor] = $value; } } $c_order = new CascadingOrder($this->id); $c_order->update( array( 'order'=>$co, 'geo_order'=>$gco ) ); if ($order['clear']!='') { $c_order->clear(); } if (count($alt_co)>0) { / the alt_cascading $c_order = new CascadingOrder($this->id,0,1); $c_order->update( array( 'order'=>$co, 'geo_order'=>$gco ) ); if ($order['clear']!='') { $c_order->clear(); } } } public function authenticate() { global $conn; global $_COOKIE; global $_POST; if ($this->disabled || $this->frozen) { $this->reason_deny = 'disabled_or_frozen'; return 0; } if ($this->username=='' || $this->password=='') { $this->reason_deny = 'rejected'; return 0; } if ($this->brute_force>=$this->brute_force_attempts && strtotime($this->date_edited." + $this->lock_time seconds")>time()) { $this->reason_deny = 'brute_force'; return 0; } if ($_COOKIE['wm_username'] == $this->username and $_COOKIE['wm_password']==$this->password and !$this->disabled and !$this->frozen) { return 1; } / Customized to recognize md5 encrypted passwords in the database if ($_POST['wm_username'] == $this->username and ($_POST['wm_password']==$this->password or md5($_POST['wm_password'])==$this->password) and !$this->disabled and !$this->frozen) { if (!$this->id || !$this->approved) { $this->reason_deny = 'not_approved'; return 0; } setcookie ("wm_id", $this->id,0); setcookie ("wm_username", $_POST['wm_username'],0); setcookie ("wm_password", $_POST['wm_password'],0); if($this->brute_force) $this->brute_force=1; $this->update(array('password' => $_POST['wm_password'])); return 1; } $this->logout(0); if($this->brute_force) $this->brute_force++; if($this->brute_force>=$this->brute_force_attempts) { $this->subject = 'Brute force attack'; $this->send_email($this->brute_force_email_template); } $this->save(); $this->reason_deny = "not_authorized"; return 0; } public function logout($redirect = 1) { setcookie ("wm_id", '',time()-3600); setcookie ("wm_username",'',time()-3600); setcookie ("wm_password", '',time()-3600); if ($redirect) header("location: webmasters.php?action=login_default&logout=1"); } public function remember($action) { global $_POST; if($action == "set") { $cookie = $_POST['wm_username']."|".$_POST['wm_password']."|".'checked'; setcookie("remember", $cookie, time()+2678400, '/'); } else { setcookie("remember", "", time()-3600, '/'); } } public function getPayout() { } public function disabled($w) { / Checks if webmaster is disabled, returns TRUE if yes. / Used in hit.phpchecks if webmaster is disabled / Peter global $conn; $sql = "SELECT disabled from $this->table where id=$w"; $res = $conn->GetRow($sql); if($res[0]==1) return true; else return false; } public function fixLangTemplate($fileName) { if(isset($_SESSION['lang'])) { if ($_SESSION['lang'] != 'en') { if (is_file(INNER_TEMPLATES_PATH.$_SESSION['lang'].'/'.$fileName)) { $exportFormFile = INNER_TEMPLATES_PATH.$_SESSION['lang'].'/'.$fileName; } else { $exportFormFile = INNER_TEMPLATES_PATH.$fileName; } } else { $exportFormFile = INNER_TEMPLATES_PATH.$fileName; } } else { $exportFormFile = INNER_TEMPLATES_PATH.$fileName; } return $exportFormFile; } } ?>