-#
- $index = 0;
- $tokens = array();
-
- $match = '(?s:)|'. # comment
- '(?s:<\?.*?\?>)|'. # processing instruction
- # regular tags
- '(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)';
-
- $parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE);
-
- foreach ($parts as $part) {
- if (++$index % 2 && $part != '')
- $tokens[] = array('text', $part);
- else
- $tokens[] = array('tag', $part);
- }
- return $tokens;
-}
-endif;
-
-
-/*
-
-PHP SmartyPants
-===============
-
-Description
------------
-
-This is a PHP translation of the original SmartyPants quote educator written in
-Perl by John Gruber.
-
-SmartyPants is a web publishing utility that translates plain ASCII
-punctuation characters into "smart" typographic punctuation HTML
-entities. SmartyPants can perform the following transformations:
-
-* Straight quotes (`"` and `'`) into "curly" quote HTML entities
-* Backticks-style quotes (` ``like this'' `) into "curly" quote HTML
- entities
-* Dashes (`--` and `---`) into en- and em-dash entities
-* Three consecutive dots (`...`) into an ellipsis entity
-
-SmartyPants does not modify characters within ``, ``, ``,
-` ';
+ echo $res;
+ }
+ else if ($results == 1)
+ {
+ $id = $result->fields['id'];
+ $name = $result->fields['first_name'].' '.$result->fields['last_name'];
+ $val = $id.'|'.$name;
+ $res = '
+ ';
+ echo $res;
+ }
+ else
+ {
+ # create the search record
+ include_once(PATH_CORE . 'search.inc.php');
+ $search = new CORE_search;
+ $arr['module'] = $this->module;
+ $arr['sql'] = $q_save;
+ $arr['limit'] = '30';
+ $arr['order_by'] = 'last_name';
+ $arr['results'] = $results;
+ $search->add($arr);
+
+ global $smarty;
+ $smarty->assign('search_id', $search->id);
+ $smarty->assign('page', '1');
+ $smarty->assign('limit', $limit);
+ $smarty->assign('order_by', $order_by);
+ $smarty->assign('results', $results);
+
+ $res = '
+ ';
+
+ echo $res;
+
+ }
+ }
+
+ ###########################################
+ ### Top Accounts Graph
+ ###########################################
+ #@todo appears to be redundant ?page=core:graphview
+ private function top($VAR)
+ {
+ global $smarty, $C_translate, $C_auth;
+
+ # Get the period type, default to month
+ if (empty($VAR['period']))
+ $p = 'm';
+ else
+ $p = $VAR['period'];
+
+ # Load the jpgraph class
+ include(PATH_GRAPH."jpgraph.php");
+ include(PATH_GRAPH."jpgraph_bar.php");
+
+ # check the validation for this function
+ if(!$C_auth->auth_method_by_name($this->module,'search')) {
+ $error = $C_translate->translate('module_non_auth','','');
+ include(PATH_GRAPH."jpgraph_canvas.php");
+ $graph = new CanvasGraph(460,55,"auto");
+ $t1 = new Text($error);
+ $t1->Pos(0.2,0.5);
+ $t1->SetOrientation("h");
+ $t1->SetBox("white","black",'gray');
+ $t1->SetFont(FF_FONT1,FS_NORMAL);
+ $t1->SetColor("black");
+ $graph->AddText($t1);
+ $graph->Stroke();
+ exit;
+ }
+
+ # Get the period start & end
+ switch ($p)
+ {
+ # By Weeks
+ case 'w':
+ $interval = "1";
+ $width = ".9";
+ $title = 'Top Accounts for Last Last Week';
+ $dow = date('w');
+ $start_str = mktime(0,0,0,date('m'), date('d')-$dow, date('y'));
+ $end_str = mktime(23,59,59,date('m'), date('d'), date('y'));
+ break;
+
+ # By Months
+ case 'm':
+ $interval = "3";
+ $width = ".6";
+ $title = 'Top Accounts for Last Last Month';
+ $start_str = mktime(0,0,0,date('m'), 1, date('y'));
+ $end_str = mktime(23,59,59,date('m'), date('d'), date('y'));
+ break;
+
+ # By Years
+ case 'y':
+ $interval = "1";
+ $width = ".8";
+ $title = 'Top Accounts for Last Last Year';
+ $start_str = mktime(0,0,0,1,1, date('y'));
+ $end_str = mktime(23,59,59, date('m'), date('d'), date('y'));
+ break;
+ }
+
+
+ ##############################@@@@@@@@
+ # Get accounts & sales for this period
+ ##############################@@@@@@@@
+ $db = &DB();
+ $sql = 'SELECT account_id,total_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
+ date_orig >= ' . $db->qstr( $start_str ) . ' AND date_orig <= ' . $db->qstr( $end_str ) . ' AND
+ site_id = ' . $db->qstr(DEFAULT_SITE);
+ $result = $db->Execute($sql);
+ if(@$result->RecordCount() == 0) {
+ $file = fopen( PATH_THEMES.'default_admin/images/invisible.gif', 'r');
+ fpassthru($file);
+ exit;
+ }
+
+ while(!$result->EOF)
+ {
+ $amt = $result->fields['total_amt'];
+ $acct = $result->fields['account_id'];
+ if(!isset( $arr[$acct] )) $arr[$acct] = 0;
+ $arr[$acct] += $amt;
+ $result->MoveNext();
+ }
+
+ $i = 0;
+ while(list($key, $var) = each(@$arr)) {
+ # Get the user name
+ $sql = 'SELECT first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account WHERE
+ id = ' . $db->qstr( $key ) . ' AND
+ site_id = ' . $db->qstr(DEFAULT_SITE);
+ $rs = $db->Execute($sql);
+
+ $_lbl[] = strtoupper(substr($rs->fields['first_name'],0,1)) . ". " . $rs->fields['last_name'];
+ $_datay[] = $var;
+ $i++;
+ }
+
+
+ ### Sort the arrays
+ array_multisort($_datay,SORT_DESC, SORT_NUMERIC, $_lbl);
+
+ ### Limit the results to 10 or less
+ for($i=0; $i=9) $i = count($_lbl);
+ }
+
+ $i = count($lbl);
+
+
+ # Get the Currency
+ $sql = 'SELECT symbol FROM ' . AGILE_DB_PREFIX . 'currency WHERE
+ id = ' . $db->qstr( DEFAULT_CURRENCY ) . ' AND
+ site_id = ' . $db->qstr(DEFAULT_SITE);
+ $rs = $db->Execute($sql);
+ $currency_iso = $rs->fields['symbol'];
+
+ // Size of graph
+ $width=265;
+ $height=75 + ($i*15);
+
+ // Set the basic parameters of the graph
+ $graph = new Graph($width,$height,'auto');
+ $graph->SetScale("textlin");
+ $graph->yaxis->scale->SetGrace(50);
+ $graph->SetMarginColor('#F9F9F9');
+ $graph->SetFrame(true,'#CCCCCC',1);
+ $graph->SetColor('#FFFFFF');
+
+ $top = 45;
+ $bottom = 10;
+ $left = 95;
+ $right = 15;
+ $graph->Set90AndMargin($left,$right,$top,$bottom);
+
+ // Label align for X-axis
+ $graph->xaxis->SetLabelAlign('right','center','right');
+
+ // Label align for Y-axis
+ $graph->yaxis->SetLabelAlign('center','bottom');
+ $graph->xaxis->SetTickLabels($lbl);
+
+ // Titles
+ $graph->title->SetFont(FF_FONT1,FS_BOLD,9.5);
+ $title = $C_translate->translate('graph_top','account_admin','');
+ $graph->title->Set($title);
+
+ // Create a bar pot
+ $bplot = new BarPlot($datay);
+ $bplot->SetFillColor("#506DC7");
+ $bplot->SetWidth(0.2);
+
+ // Show the values
+ $bplot->value->Show();
+ $bplot->value->SetFont(FF_FONT1,FS_NORMAL,8);
+ $bplot->value->SetAlign('center','center');
+ $bplot->value->SetColor("black","darkred");
+ $bplot->value->SetFormat($currency_iso.'%.2f');
+
+ $graph->Add($bplot);
+ $graph->Stroke();
+
+ return;
+ }
+
+ /**
+ * Send an email to an account
+ *
+ * @uses CORE_email
+ */
+ public function mail_one($VAR) {
+ global $C_translate,$C_debug;
+
+ # Validate the required vars (account_id, message, subject)
+ if (@$VAR['mail_account_id'] != '' && @$VAR['mail_subject'] != '' && @$VAR['mail_message'] != '') {
+ # Verify the specified account
+ $db = &DB();
+ $account = $db->Execute(sqlSelect($db,'account','email,first_name,last_name',sprintf('id=%s',$VAR['mail_account_id'])));
+
+ if ($account->RecordCount() == 0) {
+ # Error message
+ $C_debug->alert($C_translate->translate('account_non_exist',$this->module,''));
+
+ return;
+ }
+
+ # OK to send the email
+ $db = &DB();
+ $setup_email = $db->Execute(sqlSelect($db,'setup_email','*',sprintf('id=%s',$VAR['mail_email_id'])));
+
+ $E['priority'] = $VAR['mail_priority'];
+ $E['html'] = '0';
+ $E['subject'] = $VAR['mail_subject'];
+ $E['body_text'] = $VAR['mail_message'];
+ $E['to_email'] = $account->fields['email'];
+ $E['to_name'] = sprintf('%s %s',$account->fields['first_name'],$account->fields['last_name']);
+
+ if ($setup_email->fields['type'] == 0) {
+ $type = 0;
+
+ } else {
+ $type = 1;
+ $E['server'] = $setup_email->fields['server'];
+ $E['account'] = $setup_email->fields['username'];
+ $E['password'] = $setup_email->fields['password'];
+ }
+
+ $E['from_name'] = $setup_email->fields['from_name'];
+ $E['from_email'] = $setup_email->fields['from_email'];
+
+ if ($setup_email->fields['cc_list'] != '')
+ $E['cc_list'] = explode(',',$setup_email->fields['cc_list']);
+
+ if ($setup_email->fields['bcc_list'] != '')
+ $E['bcc_list'] = explode(',',$setup_email->fields['bcc_list']);
+
+ # Call the mail class
+ require_once(PATH_CORE.'email.inc.php');
+ $email = new CORE_email;
+
+ if ($type == 0)
+ $email->PHP_Mail($E);
+ else
+ $email->SMTP_Mail($E);
+
+ } else {
global $C_vars;
+
+ # Error message
+ $C_debug->alert($C_translate->translate('validate_any','',''));
$C_vars->strip_slashes_all();
return;
}
- # Get default invoice options
- $db=&DB();
- $invopt=$db->Execute(sqlSelect($db,"setup_invoice","*",""));
- if($invopt && $invopt->RecordCount()) {
- $invoice_delivery=$invopt->fields['invoice_delivery'];
- $invoice_format=$invopt->fields['invoice_show_itemized'];
- }
+ global $C_vars;
- /* hash the password */
- if(defined('PASSWORD_ENCODING_SHA'))
- $password_encoded = sha1($password);
- else
- $password_encoded = md5($password);
+ # Success message
+ $C_debug->alert($C_translate->translate('mail_sent',$this->module,''));
+ $C_vars->strip_slashes_all();
+ }
- ####################################################################
- ### Insert the account record
- ####################################################################
- $this->account_id = $db->GenID(AGILE_DB_PREFIX . 'account_id');
- $validation_str = time();
+ /**
+ * Send a mail to multiple recipients
+ * Send email to the receipients found from a search
+ *
+ * @uses CORE_email
+ * @uses CORE_search
+ */
+ public function mail_multi($VAR) {
+ global $C_translate, $C_debug;
- /** get parent id */
- $this->account_id;
- if(empty($this->parent_id)) $this->parent_id = $this->account_id;
+ # Validate the required vars (account_id, message, subject)
+ if (@$VAR['search_id'] != '' && @$VAR['mail_subject'] != '' && @$VAR['mail_message'] != '') {
- $sql = '
- INSERT INTO ' . AGILE_DB_PREFIX . 'account SET
- id = ' . $db->qstr ( $this->account_id ) . ',
- site_id = ' . $db->qstr ( DEFAULT_SITE ) . ',
- date_orig = ' . $db->qstr ( $validation_str ) . ',
- date_last = ' . $db->qstr ( time()) . ',
- language_id = ' . $db->qstr ( $VAR["account_language_id"] ) . ',
- country_id = ' . $db->qstr ( $VAR["account_country_id"] ) . ',
- parent_id = ' . $db->qstr ( $this->parent_id ) . ',
- affiliate_id = ' . $db->qstr ( @$VAR["account_affiliate_id"] ) . ',
- campaign_id = ' . $db->qstr ( @$VAR["account_campaign_id"] ) . ',
- reseller_id = ' . $db->qstr ( @$VAR["account_reseller_id"] ) . ',
- currency_id = ' . $db->qstr ( $VAR["account_currency_id"] ) . ',
- theme_id = ' . $db->qstr ( $VAR["account_theme_id"] ) . ',
- username = ' . $db->qstr ( $VAR["account_username"] , get_magic_quotes_gpc()) . ',
- password = ' . $db->qstr ( $password_encoded ) . ',
- status = ' . $db->qstr ( $status ) . ',
- first_name = ' . $db->qstr ( $VAR["account_first_name"] , get_magic_quotes_gpc()) . ',
- middle_name = ' . $db->qstr ( $VAR["account_middle_name"], get_magic_quotes_gpc()) . ',
- last_name = ' . $db->qstr ( $VAR["account_last_name"] , get_magic_quotes_gpc()) . ',
- company = ' . $db->qstr ( $VAR["account_company"] , get_magic_quotes_gpc()) . ',
- title = ' . $db->qstr ( $VAR["account_title"] , get_magic_quotes_gpc()) . ',
- email = ' . $db->qstr ( $VAR["account_email"] , get_magic_quotes_gpc()) . ',
- address1 = ' . $db->qstr ( $VAR["account_address1"] , get_magic_quotes_gpc()) . ',
- address2 = ' . $db->qstr ( $VAR["account_address2"] , get_magic_quotes_gpc()) . ',
- city = ' . $db->qstr ( $VAR["account_city"] , get_magic_quotes_gpc()) . ',
- state = ' . $db->qstr ( $VAR["account_state"] , get_magic_quotes_gpc()) . ',
- zip = ' . $db->qstr ( $VAR["account_zip"] , get_magic_quotes_gpc()) . ',
- email_type = ' . $db->qstr ( $VAR["account_email_type"] , get_magic_quotes_gpc()). ',
- invoice_delivery= ' . $db->qstr ( @$invoice_delivery ) . ',
- invoice_show_itemized=' . $db->qstr ( @$invoice_format) . ',
- invoice_advance_gen = ' . $db->qstr ( MAX_INV_GEN_PERIOD ) . ',
- invoice_grace = ' . $db->qstr ( GRACE_PERIOD ) . ',
- tax_id = ' . $db->qstr ( @$VAR['account_tax_id'] );
- $result = $db->Execute($sql);
+ # Get the search details
+ if (isset($VAR['search_id'])) {
+ include_once(PATH_CORE.'search.inc.php');
+ $search = new CORE_search;
- ####################################################################
- ### error reporting:
- ####################################################################
+ $search->get($VAR['search_id']);
+ } else {
+ # Invalid search!
+ # @todo Translate
+ echo ' The search terms submitted were invalid!';
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('account.inc.php','add', $db->ErrorMsg());
-
- if(isset($this->trigger["$type"])) {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($this->trigger["$type"], 0, $VAR);
- }
- return;
- }
-
- /* password logging class */
- if($C_list->is_installed('account_password_history')) {
- include_once(PATH_MODULES.'account_password_history/account_password_history.inc.php');
- $accountHistory = new account_password_history();
- $accountHistory->setNewPassword($this->account_id, $password_encoded);
- }
-
- ####################################################################
- ### Add the account to the default group:
- ####################################################################
-
- $group_id = $db->GenID(AGILE_DB_PREFIX . 'account_group_id');
- $sql = '
- INSERT INTO ' . AGILE_DB_PREFIX . 'account_group SET
- id = ' . $db->qstr ( $group_id ) . ',
- site_id = ' . $db->qstr ( DEFAULT_SITE ) . ',
- date_orig = ' . $db->qstr ( time() ) . ',
- group_id = ' . $db->qstr ( DEFAULT_GROUP ) . ',
- account_id = ' . $db->qstr ( $this->account_id ) . ',
- active = ' . $db->qstr ('1');
- $db->Execute($sql);
-
-
- ####################################################################
- ### Insert the static vars:
- ####################################################################
-
- $static_var->add($VAR, $this->module, $this->account_id);
-
-
- ####################################################################
- ### Mail the user the new_account email template
- ####################################################################
-
- require_once(PATH_MODULES . 'email_template/email_template.inc.php');
- $my = new email_template;
- if($status == "1")
- {
- $my->send('account_registration_active', $this->account_id, $this->account_id, '', '');
- } else {
- $validation_str = strtoupper($validation_str. ':' .$this->account_id);
- $my->send('account_registration_inactive', $this->account_id, '', '', $validation_str);
- }
-
-
- ####################################################################
- ### Add the newsletters
- ####################################################################
-
- if(NEWSLETTER_REGISTRATION == "1")
- {
- @$VAR['newsletter_html'] = $VAR['account_email_type'];
- $VAR['newsletter_email'] = $VAR['account_email'];
- $VAR['newsletter_first_name'] = $VAR['account_first_name'];
- $VAR['newsletter_last_name'] = $VAR['account_last_name'];
- require_once(PATH_MODULES . '/newsletter/newsletter.inc.php');
- $newsletter = new newsletter;
- $newsletter->subscribe($VAR, $this);
- }
-
-
- ####################################################################
- ### Log in the user & display the welcome message
- ####################################################################
-
- if($status == "1")
- {
- if($this->parent_id == $this->account_id || empty($this->parent_id))
- {
- $C_debug->alert($C_translate->translate("user_add_active_welcome","account",""));
- if(SESSION_EXPIRE == 0) $exp = 99999;
- else $exp = SESSION_EXPIRE;
- $date_expire = (time() + (SESSION_EXPIRE * 60));
-
- # update the session
- $db = &DB();
- $q = "UPDATE " . AGILE_DB_PREFIX . "session
- SET
- ip= " . $db->qstr(USER_IP) .",
- date_expire = " . $db->qstr($date_expire) . ",
- logged = " . $db->qstr('1').",
- account_id = " . $db->qstr($this->account_id) . "
- WHERE
- id = " . $db->qstr(SESS) . "
- AND
- site_id = " . $db->qstr(DEFAULT_SITE);
- $result = $db->Execute($q);
-
- ### constants
- define('FORCE_SESS_ACCOUNT', $this->account_id);
- define('FORCE_SESS_LOGGED', 1);
-
- ### Reload the session auth cache
- if(CACHE_SESSIONS == '1') {
- $force = true;
- $C_auth = new CORE_auth($force);
- global $C_auth2;
- $C_auth2 = $C_auth;
- }
-
- if(isset($VAR['_page_next']))
- define('REDIRECT_PAGE', '?_page='.$VAR['_page_next']);
- elseif(isset($VAR['_page']))
- define('REDIRECT_PAGE', '?_page='.$VAR['_page']);
+ return;
}
- ####################################################################
- ### Do any db_mapping
- ####################################################################
- if($C_list->is_installed('db_mapping'))
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- if(!empty($password))
- $db_map->plaintext_password = $password;
+ # Generate the full query
+ $field_list = sprintf('%saccount.email,%saccount.first_name,%saccount.last_name',AGILE_DB_PREFIX,AGILE_DB_PREFIX,AGILE_DB_PREFIX);
+
+ $q = str_replace('%%fieldList%%',$field_list,$search->sql);
+ $q = str_replace('%%tableList%%',AGILE_DB_PREFIX.'account',$q);
+ $q = str_replace('%%whereList%%','',$q);
+
+ $q .= sprintf('%saccount.site_id=%s',AGILE_DB_PREFIX,DEFAULT_SITE);
+ $db = &DB();
+ $account = $db->Execute($q);
+
+ # Check results
+ if ($account->RecordCount() == 0) {
+ $C_debug->alert($C_translate->translate('account_non_exist',$this->module,''));
+
+ return;
+ }
+
+ # Get the selected email setup details
+ $db = &DB();
+ $setup_email = $db->Execute(sqlSelect($db,'setup_email','*',sprintf('id=%s',$VAR['mail_email_id'])));
+ if ($setup_email->fields['type'] == 0) {
+ $type = 0;
+
+ } else {
+ $type = 1;
+
+ $E['server'] = $setup_email->fields['server'];
+ $E['account'] = $setup_email->fields['username'];
+ $E['password'] = $setup_email->fields['password'];
+ }
+
+ $E['priority'] = $VAR['mail_priority'];
+ $E['html'] = '0';
+ $E['subject'] = $VAR['mail_subject'];
+ $E['body_text'] = $VAR['mail_message'];
+ $E['from_name'] = $setup_email->fields['from_name'];
+ $E['from_email'] = $setup_email->fields['from_email'];
+
+ # Loop to send each e-mail
+ while (! $account->EOF) {
+ $E['to_email'] = $account->fields['email'];
+ $E['to_name'] = sprintf('%s %s',$account->fields['first_name'],$account->fields['last_name']);
+
+ # Call the mail class
+ require_once(PATH_CORE.'email.inc.php');
+ $email = new CORE_email;
+
+ if ($type == 0)
+ $email->PHP_Mail($E);
else
- $db_map->plaintext_password = false;
- $db_map->account_add ( $this->account_id );
+ $email->SMTP_Mail($E);
- $db_map = new db_mapping;
- $db_map->login ( $this->account_id );
- }
-
- ####################################################################
- ### Affiliate Auto Creation
- ####################################################################
- if(AUTO_AFFILIATE == 1 && $C_list->is_installed("affiliate"))
- {
- $VAR['affiliate_account_id'] = $this->account_id;
- $VAR['affiliate_template_id'] = DEFAULT_AFFILIATE_TEMPLATE;
-
- include_once(PATH_MODULES . 'affiliate/affiliate.inc.php');
- $affiliate = new affiliate;
- $affiliate->add($VAR, $affiliate);
- }
- } else {
- $C_debug->alert($C_translate->translate("user_add_inactive_welcome","account",""));
- define('FORCE_PAGE', 'core:blank');
- }
- }
-
-
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
-
- ### Check that user is logged in:
- if(SESS_LOGGED != '1') {
- echo "Sorry, you must be logged in!";
- return false;
- }
-
- $this->account_construct();
-
- /* check for sub account */
- if(!empty($VAR['id']) && $VAR['id'] != SESS_ACCOUNT) {
- if($this->isParentAccount($VAR['id'])) {
- $VAR['account_id'] = $VAR['id'];
- global $smarty;
- $smarty->assign('issubaccount', true);
- } else {
- return false;
- }
- } else {
- $VAR['id'] = SESS_ACCOUNT;
- $VAR['account_id'] = SESS_ACCOUNT;
- }
-
- ### Retrieve the record:
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
-
-
- ### Get the static vars:
- global $smarty;
- require_once(PATH_CORE . 'static_var.inc.php');
- $static_var = new CORE_static_var;
- $arr = $static_var->update_form('account', 'update', SESS_ACCOUNT);
- if(gettype($arr) == 'array') {
- $smarty->assign('static_var', $arr);
- } else {
- $smarty->assign('static_var', false);
- }
-
- /* get child accounts */
- if(empty($smarty->_tpl_vars['account'][0]['parent_id']) || $smarty->_tpl_vars['account'][0]['parent_id']==$smarty->_tpl_vars['account'][0]['id']) {
- $db=&DB();
- $rs = $db->Execute(sqlSelect($db,"account","id,first_name,last_name,email,username","parent_id=". $db->qstr(SESS_ACCOUNT)));
- if($rs && $rs->RecordCount()) {
- while(!$rs->EOF) {
- $smart[] = $rs->fields;
- $rs->MoveNext();
- }
- $smarty->assign('subaccount', $smart);
+ # Next record
+ $account->MoveNext();
}
- }
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- global $VAR;
-
- ### Check that user is logged in:
- if(SESS_LOGGED != '1')
- echo "Sorry, you must be logged in!";
-
-
- /* check for sub account */
- $issubaccount=false;
- if(!empty($VAR['account_id']) && $VAR['account_id'] != SESS_ACCOUNT) {
- if($this->isParentAccount($VAR['account_id'])) {
- $VAR['id'] = $VAR['account_id'];
- global $smarty;
- $issubaccount=true;
- } else {
- return false;
- }
} else {
- $VAR['id'] = SESS_ACCOUNT;
- $VAR['account_id'] = SESS_ACCOUNT;
- }
+ global $C_vars;
- $VAR['account_date_last']=time();
-
-
- // validate the tax_id
- require_once(PATH_MODULES.'tax/tax.inc.php');
- $taxObj=new tax;
- $tax_arr = @$VAR['account_tax_id'];
- if(is_array($tax_arr)) {
- foreach($tax_arr as $country_id => $tax_id) {
- if ($country_id == $VAR['cid']) {
- $exempt = @$VAR["account_tax_id_exempt"][$country_id];
- if(!$txRs=$taxObj->TaxIdsValidate($country_id, $tax_id, $exempt)) {
- $this->validated = false;
- global $C_translate;
- $this->val_error[] = array(
- 'field' => 'account_tax_id',
- 'field_trans' => $taxObj->errField,
- 'error' => $C_translate->translate('validate_general', "", ""));
- }
- if($exempt)
- $VAR['account_tax_id']=false;
- else
- $VAR['account_tax_id']=$tax_id;
- }
- }
- }
-
- ####################################################################
- ### Get required static_Vars and validate them... return an array
- ### w/ ALL errors...
- ####################################################################
-
- require_once(PATH_CORE . 'static_var.inc.php');
- $static_var = new CORE_static_var;
- if(!isset($this->val_error)) $this->val_error = false;
- $all_error = $static_var->validate_form('account', $this->val_error);
-
- if($all_error != false && gettype($all_error) == 'array')
- $this->validated = false;
- else
- $this->validated = true;
-
-
-
- ####################################################################
- # If validation was failed, skip the db insert &
- # set the errors & origonal fields as Smarty objects,
- # and change the page to be loaded.
- ####################################################################
-
- if(!$this->validated)
- {
- global $smarty;
-
- # set the errors as a Smarty Object
- $smarty->assign('form_validation', $all_error);
-
- # set the page to be loaded
- if(!defined("FORCE_PAGE"))
- {
- define('FORCE_PAGE', $VAR['_page_current']);
- }
+ # Error message
+ $C_debug->alert($C_translate->translate('validate_any','',''));
+ $C_vars->strip_slashes_all();
return;
}
+ global $C_vars;
- ### Change password
- $password_changed = false;
- if(isset($VAR['account_password']) && $VAR['account_password'] != "")
- {
- if(isset($VAR['confirm_password']) && $VAR['account_password'] == $VAR['confirm_password'])
- {
- $password = $VAR['account_password'];
- unset($VAR['account_password']);
- @$VAR["account_password"] = $password;
- ### Alert: the password has been changed!
- global $C_debug, $C_translate;
- $C_debug->alert($C_translate->translate('password_changed','account',''));
- $password_changed=true;
+ # Success message
+ $C_debug->alert($C_translate->translate('mail_sent',$this->module,''));
+ $C_vars->strip_slashes_all();
+ }
- /* check if new password is ok */
- global $C_list;
- if($C_list->is_installed('account_password_history')) {
- include_once(PATH_MODULES.'account_password_history/account_password_history.inc.php');
- $accountHistory = new account_password_history();
- if(!$accountHistory->getIsPasswordOk(SESS_ACCOUNT, $VAR['account_password'], false)) {
- $C_debug->alert("The password you have selected has been used recently and cannot be used again at this time for security purposes.");
- unset($VAR["account_password"]);
- $password_changed=false;
- }
- }
+ /**
+ * Send Password Reminder
+ *
+ * @uses email_template
+ */
+ public function send_password_email($VAR) {
+ global $C_translate,$C_debug;
+
+ require_once(PATH_MODULES.'email_template/email_template.inc.php');
+ $my = new email_template;
+
+ $my->send('password_change_instructions',@$VAR['id'],'','','');
+ echo $C_translate->translate('password_change_instructions',$this->module,'');
+ }
+
+ /**
+ * Send users verification email
+ *
+ * @uses email_template
+ */
+ public function send_verify_email($VAR) {
+ global $C_translate,$C_debug;
+
+ require_once(PATH_MODULES.'email_template/email_template.inc.php');
+ $my = new email_template;
+
+ $db = &DB();
+ $result = $db->Execute(sqlSelect($db,'account','date_orig',sprintf('id=%s',$VAR['id'])));
+
+ $my->send('account_registration_inactive',$VAR['id'],$VAR['id'],'',$this->validation_str($VAR['id']));
+ echo $C_translate->translate('account_verify_instructions',$this->module,'');
+ }
+
+ /**
+ * Add new accounts
+ *
+ * @uses CORE_validate
+ * @uses email_template
+ * @uses affiliate
+ */
+ public function add($VAR) {
+ global $C_list,$C_translate,$C_debug,$smarty;
+
+ if (! empty($VAR['account_date_expire'])) {
+ include_once(PATH_CORE.'validate.inc.php');
+ $val = new CORE_validate($VAR);
+
+ $VAR['account_date_expire'] = $val->convert_date($VAR['account_date_expire']);
+ } else {
+ $VAR['account_date_expire'] = 0;
+ }
+
+ # If the username is blank, auto generate one
+ if (empty($VAR['account_username'])) {
+ $VAR['account_username'] = '';
+ $length = 4;
+ srand((double)microtime()*1000000);
+ $vowels = array('a','e','i','o','u');
+ $cons = array('b','c','d','g','h','j','k','l','m','n','p','r','s','t','u','v','w','tr','cr','br','fr','th','dr','ch','ph','wr','st','sp','sw','pr','sl','cl');
+
+ $num_vowels = count($vowels);
+ $num_cons = count($cons);
+ for ($i=0; $i<$length; $i++)
+ $VAR['account_username'] .= $cons[rand(0,$num_cons-1)].$vowels[rand(0,$num_vowels-1)];
+ }
+
+ # If the password is blank, auto generate one
+ if (empty($VAR['account_password'])) {
+ $passwd = '********';
+
+ srand((double)microtime() * 1000000);
+ $UniqID = md5(uniqid(rand()));
+ $VAR['account_password'] = substr(md5(uniqid(rand())),0,10);
+
+ } else {
+ $passwd = $VAR['account_password'];
+ }
+
+ # Add the record
+ if (! $this->account_id = parent::add($VAR))
+ return;
+
+ # Add the account to the groups
+ $this->add_account_groups($VAR['groups'],$this->account_id,$VAR['account_date_expire']);
+
+ # Mail the new user
+ if (! empty($VAR['welcome_email'])) {
+ require_once(PATH_MODULES.'email_template/email_template.inc.php');
+ $my = new email_template;
+
+ if ($VAR['account_status'] == '1')
+ $my->send('account_add_staff_active',$this->account_id,'','',$passwd);
- }
else
- {
- ### ERROR: The passwords provided do not match!
- global $C_debug, $C_translate;
- $C_debug->alert($C_translate->translate('password_change_match','account',''));
- unset($VAR["account_password"]);
- }
+ $my->send('account_add_staff_inactive',$this->account_id,$this->account_id,'',$this->validation_str($this->account_id));
}
+
+ # Display the welcome message
+ if ($VAR['account_status'] == '1')
+ $C_debug->alert($C_translate->translate('staff_add_active',$this->module,''));
else
- {
- unset($VAR["account_password"]);
+ $C_debug->alert($C_translate->translate('staff_add_inactive',$this->module,''));
+
+ # Affiliate Auto Creation
+ if (AUTO_AFFILIATE == 1 && $C_list->is_installed('affiliate')) {
+ $VAR['affiliate_account_id'] = $this->account_id;
+ $VAR['affiliate_template_id'] = DEFAULT_AFFILIATE_TEMPLATE;
+ $VAR['affiliate_parent_affiliate_id'] = $VAR['account_affiliate_id'];
+
+ include_once(PATH_MODULES.'affiliate/affiliate.inc.php');
+ $affiliate = new affiliate;
+
+ $affiliate->add($VAR,$affiliate);
}
-
- ### Change theme
- if(isset($VAR['tid']) && $VAR['tid'] != "")
- @$VAR["account_theme_id"] = $VAR['tid'];
-
-
- ### Change Language
- if(isset($VAR['lid']) && $VAR['lid'] != "")
- @$VAR["account_language_id"] = $VAR['lid'];
-
-
- ### Change country
- if(isset($VAR['cid']) && $VAR['cid'] != "")
- @$VAR["account_country_id"] = $VAR['cid'];
-
-
- ### Change currency
- if(isset($VAR['cyid']) && $VAR['cyid'] != "")
- @$VAR["account_currency_id"] = $VAR['cyid'];
-
- ### Get the old username ( for db mapping )
- $db = &DB();
- $sql = 'SELECT username FROM ' . AGILE_DB_PREFIX . 'account WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr(SESS_ACCOUNT);
- $result = $db->Execute($sql);
- if($result->RecordCount() > 0)
- {
- $old_username = $result->fields['username'];
- }
-
- ### Update the record
- $this->account_construct();
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
-
-
- /* password logging class */
- if($password_changed && is_object($accountHistory)) $accountHistory->setNewPassword(SESS_ACCOUNT, $VAR['account_password'], false);
-
-
-
- ### Update the static vars:
- $static_var->update($VAR, 'account', SESS_ACCOUNT);
-
- ### Do any db_mapping
- global $C_list;
- if($C_list->is_installed('db_mapping'))
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- if(!empty($password))
- $db_map->plaintext_password = $password;
- else
- $db_map->plaintext_password = false;
- $db_map->account_edit ( SESS_ACCOUNT, $old_username );
- }
-
- /* update groups for subaccount */
- if($issubaccount) {
- $db=&DB();
- $db->Execute(sqlDelete($db,"account_group","group_id>2 and
- (service_id is null or service_id=0 or service_id='')
- and account_id=".$db->qstr($VAR['account_id'])));
- if(!empty($VAR['groups']))
- {
- global $C_auth;
- foreach($VAR['groups'] as $gid=>$val) {
- if($gid==$val && $C_auth->auth_group_by_id($gid)) {
- $fields=Array('account_id'=>$VAR['account_id'], 'group_id'=>$gid, 'active'=>1, 'date_orig'=>time() );
- $db->Execute(sqlInsert($db,"account_group",$fields));
- }
- }
- }
- }
+ return;
}
-
-
- ##############################
- ## PASSWORD ##
- ##############################
-
- function password($VAR)
- {
- ### Set the max time between password requests:
- $LIMIT_SECONDS = 120;
-
- global $C_translate, $C_debug;
-
- ### Is the username & email both set?
- if(!isset($VAR["account_email"]) && !isset($VAR["account_username"]) )
- {
- #### ERROR: You must enter either your username or e-mail address!
- $C_debug->alert($C_translate->translate('password_reset_req','account',''));
- return;
- }
- else if($VAR["account_email"] == "" && $VAR["account_username"] == "")
- {
- #### ERROR: You must enter either your username or e-mail address!
- $C_debug->alert($C_translate->translate('password_reset_req','account',''));
- return;
- }
+ /**
+ * View an Account
+ */
+ public function view($VAR) {
+ global $C_auth;
$db = &DB();
- if(isset($VAR["account_email"]) && $VAR["account_email"] != "")
- {
- $sql = ' email = '. $db->qstr($VAR["account_email"], get_magic_quotes_gpc());
- }
- else if(isset($VAR["account_username"]) && $VAR["account_username"] != "")
- {
- $sql = ' username = '. $db->qstr($VAR["account_username"], get_magic_quotes_gpc());
- }
+ # Get our results
+ $smart = parent::view($VAR);
+ if ($smart) {
+ # Get any authorized groups
+ $view = $db->Execute(sqlSelect($db,'account_group','service_id,group_id',array('account_id'=>$VAR['id'],'active'=>1),'group_id'));
- $q = 'SELECT id,email,first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account
- WHERE '. $sql . ' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $result = $db->Execute($q);
+ while (! $view->EOF) {
+ $smart['groups'] = array();
+
+ if ($view->fields['service_id'] == '')
+ array_push($smart['groups'],$view->fields['group_id']);
+
+ $view->MoveNext();
+ }
+
+ # Verify the user has access to view this account
+ if (SESS_ACCOUNT != $VAR['id']) {
+ $smart['own_account'] = false;
+
+ $display_this = true;
+ for ($ix=0; $ixauth_group_by_id($group[$ix]))
+ $display_this = false;
+
+ } else {
+ $display_this = true;
+ $smart['own_account'] = true;
+ }
+
+ # define the results
+ if (! $display_this) {
+ unset($smart);
+ echo 'You have selected an account for which you are not authorized, your permission settings are to low! ';
+
+ continue;
+ }
+
+ # Get the last activity date/IP
+ $view = $db->SelectLimit(sqlSelect($db,'login_log','*',array('account_id'=>$VAR['id']),'date_orig DESC'),1);
+
+ if ($view && $view->RecordCount() == 1) {
+ $smart['last_activity'] = $view->fields['date_orig'];
+ $smart['last_ip'] = $view->fields['ip'];
+ } else {
+ $smart['last_activity'] = '';
+ $smart['last_ip'] = '';
+ }
+
+ # Get invoice details for this account
+ $view = $db->SelectLimit(sqlSelect($db,'invoice','id,date_orig,total_amt,billed_amt,process_status',array('account_id'=>$VAR['id']),'id DESC'),10);
+ if ($view && $view->RecordCount() > 0) {
+ $smart['invoice'] = array();
+
+ while (! $view->EOF) {
+ if ($view->fields['total_amt'] > $view->fields['billed_amt'] && $view->fields['suspend_billing'] != 1)
+ $view->fields['due'] = $view->fields['total_amt']-$view->fields['billed_amt'];
+
+ array_push($smart['invoice'],$view->fields);
+ $view->MoveNext();
+ }
+ }
+
+ # Get service details for this account
+ $view = $db->SelectLimit(sqlSelect($db,'service','id,sku,price,active,type,domain_name,domain_tld',array('account_id'=>$VAR['id']),'id DESC'),10);
+ if ($view && $view->RecordCount() > 0) {
+ $smart['service'] = array();
+
+ while (! $view->EOF) {
+ array_push($smart['service'],$view->fields);
+ $view->MoveNext();
+ }
+ }
+
+ # Get invoices to be generated for this account
+ include_once(PATH_MODULES.'invoice/invoice.inc.php');
+ $invoice = new invoice;
+
+ $view = $db->Execute($invoice->sql_invoice_soon(null,null,$VAR['id']));
+ if ($view && $view->RecordCount() > 0) {
+ $smart['duesoon'] = array();
+
+ while (! $view->EOF) {
+ array_push($smart['duesoon'],$view->fields);
+ $view->MoveNext();
+ }
+ }
+
+ # No results
+ } else {
+ global $C_debug;
+ $C_debug->error(__FILE__,__METHOD__,'The selected record does not exist any longer, or your account is not authorized to view it');
- if($result->RecordCount() == 0)
- {
- ### ERROR: No matches found!
- $C_debug->alert($C_translate->translate('password_reset_no_match','account',''));
return;
}
- $account = $result->fields["id"];
-
- ###################################################################
- ### Check that this email has not been requested already
- ### In the last 60 seconds
-
- $db = &DB();
- $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'temporary_data WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- field1 = ' . $db->qstr($account);
- $result = $db->Execute($sql);
- if($result->RecordCount() > 0)
- {
- $limit = $result->fields['date_orig'] + $LIMIT_SECONDS;
-
- if($limit > time())
- {
- $error1 = $C_translate->translate("password_reset_spam_limit","account","");
- $error = ereg_replace('%limit%', "$LIMIT_SECONDS", $error1);
- $C_debug->alert( $error );
- return;
- }
- else
- {
- ### Delete the old request
- $sql = 'DELETE FROM ' . AGILE_DB_PREFIX . 'temporary_data WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- field1 = ' . $db->qstr($account);
- $db->Execute($sql);
- }
-
- }
-
-
- ###################################################################
- ### Ok to continue:
-
- $now = md5(microtime());
- $expire = time() + (15*60); // expires in 15 minutes
-
-
- #####################################################
- ### Create the temporary DB Record:
-
- $db = &DB();
- $id = $db->GenID(AGILE_DB_PREFIX . "" . 'temporary_data_id');
- $sql = 'INSERT INTO ' . AGILE_DB_PREFIX . 'temporary_data SET
- site_id = ' . $db->qstr(DEFAULT_SITE) . ',
- id = ' . $db->qstr($id) . ',
- date_orig = ' . $db->qstr(time()) . ',
- date_expire = ' . $db->qstr($expire) . ',
- field1 = ' . $db->qstr($account) . ',
- field2 = ' . $db->qstr($now);
- $result = $db->Execute($sql);
-
-
- #####################################################
- ### Send the password reset email template:
-
- require_once(PATH_MODULES . 'email_template/email_template.inc.php');
- $my = new email_template;
- $my->send('account_reset_password', $account, '', '', $now);
-
- ### ALERT: we have sent an email to you....
- $C_debug->alert($C_translate->translate('password_reset_sent','account',''));
+ global $smarty;
+ $smarty->assign('record',$smart);
}
+ /**
+ * Update an account
+ */
+ public function update($VAR) {
+ if (isset($VAR['process_account_password']) && $VAR['process_account_password'])
+ $VAR['account_password'] = $VAR['process_account_password'];
+ $ok = parent::update($VAR);
-
- ##############################
- ## PASSWORD RESET ##
- ##############################
-
- function password_reset($VAR)
- {
- global $C_translate, $C_debug, $smarty;
-
- ### Validate that the password is set... && confirm password is set...
- if(!isset($VAR['account_password']) || !isset($VAR['confirm_password']))
- {
- ### ERROR:
- $message = $C_translate->translate('password_reset_reqq','account','');
- $C_debug->alert($message);
- return;
- }
- else if ($VAR['account_password'] == "")
- {
- ### ERROR:
- $message = $C_translate->translate('password_reset_reqq','account','');
- $C_debug->alert($message);
- return;
- }
- else if ($VAR['account_password'] != $VAR['confirm_password'])
- {
- ### ERROR:
- $message = $C_translate->translate('password_change_match','account','');
- $C_debug->alert($message);
- return;
- }
- else
- {
- $plaintext_password = $VAR['account_password'];
-
- /* hash the password */
- if(defined('PASSWORD_ENCODING_SHA'))
- $password = sha1($VAR['account_password']);
- else
- $password = md5($VAR['account_password']);
- }
-
-
- if(!isset($VAR['validate']) || $VAR['validate'] == "")
- {
- ### ERROR: bad link....
- $url = '' . $C_translate->translate('submit','CORE','') . ' ';
- $message = $C_translate->translate('password_reset_bad_url','account','');
- $C_debug->alert($message . '' . $url);
- return;
- }
-
-
- ### Get the temporary record from the database
- $validate = @$VAR['validate'];
- $db = &DB();
- $sql = 'SELECT field1,field2 FROM ' . AGILE_DB_PREFIX . 'temporary_data WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- date_expire >= '. $db->qstr(time()) . ' AND
- field2 = ' . $db->qstr($validate);
- $result = $db->Execute($sql);
-
- if($result->RecordCount() == 0)
- {
- ### ERROR: no match for submitted link, invalid or expired.
- $url = '' . $C_translate->translate('submit','CORE','') . ' ';
- $message = $C_translate->translate('password_reset_bad_url','account','');
- $C_debug->alert($message . '' . $url);
- return;
- }
-
- $account_id = $result->fields['field1'];
-
- /* check if new password is ok */
- global $C_list;
- if($C_list->is_installed('account_password_history')) {
- include_once(PATH_MODULES.'account_password_history/account_password_history.inc.php');
- $accountHistory = new account_password_history();
- if(!$accountHistory->getIsPasswordOk($account_id, $password)) {
- $C_debug->alert("The password you have selected has been used recently and cannot be used again at this time for security purposes.");
- return;
+ if ($ok) {
+ # Remove login lock
+ if ($VAR['account_status']) {
+ $db = &DB();
+ $delrs = $db->Execute(sqlDelete($db,'login_lock',sprintf('account_id=%s',$VAR['account_id'])));
+ $delrs = $db->Execute(sqlDelete($db,'login_log',sprintf('account_id=%s AND status=0',$VAR['account_id'])));
}
+
+ return true;
}
-
-
- ###############################################################
- ### Delete the temporary record
- $sql = 'DELETE FROM ' . AGILE_DB_PREFIX . 'temporary_data WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- field2 = ' . $db->qstr($validate);
- $db->Execute($sql);
-
-
- ###############################################################
- ### Update the password record:
- $db = &DB();
- $sql = 'UPDATE ' . AGILE_DB_PREFIX . 'account
- SET
- date_last = ' . $db->qstr(time()) . ',
- password = ' . $db->qstr($password) . '
- WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($account_id);
- $db->Execute($sql);
-
- /* password logging class */
- if(!empty($accountHistory) && is_object($accountHistory)) $accountHistory->setNewPassword($account_id, $password);
-
-
- ####################################################################
- ### Get the old username ( for db mapping )
-
- $db = &DB();
- $sql = 'SELECT username FROM ' . AGILE_DB_PREFIX . 'account WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($account_id);
- $result = $db->Execute($sql);
- if($result->RecordCount() > 0)
- {
- $old_username = $result->fields['username'];
- }
-
- ####################################################################
- ### Do any db_mapping
- ####################################################################
- global $C_list;
- if($C_list->is_installed('db_mapping'))
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- $db_map->plaintext_password = $plaintext_password;
- $db_map->account_edit ( $account_id, $old_username );
- }
-
-
- ### Return the success message:
- $C_debug->alert($C_translate->translate('password_update_success','account',''));
- $smarty->assign('pw_changed', true);
- }
-
-
-
- ##############################
- ## VERIFY ACCOUNT ##
- ##############################
-
- function verify($VAR)
- {
- global $C_debug, $C_translate, $smarty;
-
- ### Validate $verify is set...
- if(!isset($VAR['verify']) || $VAR['verify'] == "")
- {
- ### Error: please use the form below ...
- $smarty->assign('verify_results', false);
- return;
- }
-
- @$verify = explode(':', $VAR['verify']);
-
- ### Validate the $verify string....
- $db = &DB();
- $sql = 'SELECT id,username,status FROM ' . AGILE_DB_PREFIX . 'account WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr(@$verify[1]) . ' AND
- date_orig = ' . $db->qstr(@$verify[0]);
- $result = $db->Execute($sql);
- if($result->RecordCount() == 0)
- {
- ### Error: please use the form below ...
- $smarty->assign('verify_results', false);
- return;
- }
-
-
- ### Check the status:
- $status = $result->fields['status'];
- $username = $result->fields['username'];
- if($status == "1")
- {
- ### Account already active!
- $smarty->assign('verify_results', true);
- return;
- }
-
- ### Update the account status
- $sql = 'UPDATE ' . AGILE_DB_PREFIX . 'account SET
- status = ' . $db->qstr("1") . '
- WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr(@$verify[1]);
- $result = $db->Execute($sql);
-
-
- ### Account now active!
- $smarty->assign('verify_results', true);
-
-
- ### Return the success message:
- $C_debug->alert($C_translate->translate('password_update_success','account',''));
-
-
- ####################################################################
- ### Do any db_mapping
- ####################################################################
- global $C_list;
- /*
- if($C_list->is_installed('db_mapping'))
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- $db_map->account_edit ( $VAR['verify'], $username );
- }
- */
- if($C_list->is_installed('db_mapping') )
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- $db_map->plaintext_password = false;
- $db_map->account_add ( $verify[1] );
- }
}
-
-
-
- ##############################
- ## VERIFY ACCOUNT ##
- ##############################
-
- function verify_resend($VAR)
- {
- global $C_translate, $C_debug;
-
- ### Is the username & email both set?
- if(!isset($VAR["account_email"]) && !isset($VAR["account_username"]) )
- {
- #### ERROR: You must enter either your username or e-mail address!
- $C_debug->alert($C_translate->translate('verify_resend_req','account',''));
- return;
- }
- else if($VAR["account_email"] == "" && $VAR["account_username"] == "")
- {
- #### ERROR: You must enter either your username or e-mail address!
- $C_debug->alert($C_translate->translate('verify_resend_req','account',''));
- return;
- }
+ /**
+ * Merge two accounts together
+ *
+ * @uses CORE_auth
+ */
+ public function merge($VAR) {
+ global $C_auth,$C_list,$C_translate,$C_debug;
$db = &DB();
- if(isset($VAR["account_email"]) && $VAR["account_email"] != "")
- {
- $sql = ' email = '. $db->qstr($VAR["account_email"], get_magic_quotes_gpc());
- }
- else if(isset($VAR["account_username"]) && $VAR["account_username"] != "")
- {
- $sql = ' username = '. $db->qstr($VAR["account_username"], get_magic_quotes_gpc());
+ if (empty($VAR['id']) || empty($VAR['merge_acct_id'])) {
+ $C_debug->alert($C_translate->translate('merge_err',$this->module,''));
+
+ return false;
}
+ $acct_id = $VAR['id'];
+ $merge_acct_id = $VAR['merge_acct_id'];
- $q = 'SELECT id,date_orig,status,email,first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account
- WHERE '. $sql . ' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $result = $db->Execute($q);
+ # Get merged account_group
+ $rs = $db->Execute(sqlSelect($db,'account_group','*',sprintf("(service_id = '' OR service_id = 0 OR service_id IS NULL) AND account_id=%s",$acct_id)));
+ if ($rs === false) {
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
- if($result->RecordCount() == 0)
- {
- ### ERROR: No matches found!
- $C_debug->alert($C_translate->translate('password_reset_no_match','account',''));
- return;
- }
- $account = $result->fields["id"];
- $status = $result->fields["status"];
- $validation_str = strtoupper($result->fields['date_orig']. ':' . $result->fields['id']);
+ } else {
+ while (! $rs->EOF) {
+ $Cauth = new CORE_auth(true);
- if($status == "1")
- {
- ### ERROR: This account is already active!
- $C_debug->alert($C_translate->translate('verify_resend_active','account',''));
- return;
+ if ($Cauth->auth_group_by_account_id($merge_acct_id,$rs->fields['group_id']))
+ # Duplicate group, delete
+ $db->Execute(sqlDelete($db,'account_group',sprintf('id=%s',$rs->fields['id'])));
+
+ $rs->MoveNext();
+ }
}
- ### Resend the pending email:
- require_once(PATH_MODULES . 'email_template/email_template.inc.php');
- $my = new email_template;
- $my->send('account_registration_inactive', $account, $account, '', $validation_str);
+ # Default table
+ $merge = array(
+ 'account_group'=>'account_id',
+ 'account_billing'=>'account_id',
+ 'cart'=>'account_id',
+ 'charge'=>'account_id',
+ 'discount'=>'avail_account_id',
+ 'invoice'=>'account_id',
+ 'log_error'=>'account_id',
+ 'login_lock'=>'account_id',
+ 'login_log'=>'account_id',
+ 'search'=>'account_id',
+ 'service'=>'account_id',
+ 'session'=>'account_id',
+ 'staff'=>'account_id'
+ );
- ### Notice that the email is sent:
- $C_debug->alert($C_translate->translate("user_add_inactive_welcome","account",""));
+ # Affiliate
+ if ($C_list->is_installed('affiliate'))
+ $merge['affiliate'] = 'account_id';
+ foreach ($merge as $table => $field) {
+ $rs = $db->Execute(sqlUpdate($db,$table,array($field=>$acct_id),sprintf('%s=%s',$field,$merge_acct_id)));
+
+ if ($rs === false)
+ $C_debug->error(__FILE__,sprintf('%s::%s',__METHOD__,$table),$db->ErrorMsg());
+ }
+
+ # Delete account
+ $rs = $db->Execute(sqlDelete($db,'account',sprintf('id=%s',$merge_acct_id)));
+ if ($rs === false)
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+
+ $C_debug->alert($C_translate->translate('merge_ok',$this->module,''));
+
+ return;
}
+ /**
+ * Delete an account
+ *
+ * @uses invoice
+ */
+ public function delete($VAR) {
+ global $C_list;
- ##############################
- ## STATIC VARS ##
- ##############################
+ $db = &DB();
- function static_var($VAR)
- {
- global $smarty;
- require_once(PATH_CORE . 'static_var.inc.php');
- $static_var = new CORE_static_var;
+ # Generate the list of ID's
+ $id_list = '';
+ $account_id_list = '';
+ $discount_id_list = '';
+ if (isset($VAR['delete_id']))
+ $ids = explode(',',preg_replace('/,$/','',$VAR['delete_id']));
+ elseif (isset($VAR['id']))
+ $ids = explode(',',preg_replace('/,$/','',$VAR['id']));
- if(ereg('search', $VAR['_page']))
- $arr = $static_var->generate_form('account', 'add', 'search');
- else
- $arr = $static_var->generate_form('account', 'add', 'update');
+ # Verify this is not the admin account or the current user's account
+ if (($i = array_search(SESS_ACCOUNT,$ids)) || ($i = array_search(1,$ids)))
+ unset($ids[$i]);
- if(gettype($arr) == 'array')
- {
- ### Set everything as a smarty array, and return:
- $smarty->assign('show_static_var', true);
- $smarty->assign('static_var', $arr);
- return true;
+ $this->associated_DELETE = array();
+ array_push($this->associated_DELETE,array('table'=>'session','field'=>'account_id'));
+ array_push($this->associated_DELETE,array('table'=>'account_billing','field'=>'account_id'));
+ array_push($this->associated_DELETE,array('table'=>'account_group','field'=>'account_id'));
+ array_push($this->associated_DELETE,array('table'=>'cart','field'=>'account_id'));
+ array_push($this->associated_DELETE,array('table'=>'search','field'=>'account_id'));
+ array_push($this->associated_DELETE,array('table'=>'staff','field'=>'account_id'));
+ array_push($this->associated_DELETE,array('table'=>'discount','field'=>'account_id'));
+ if ($C_list->is_installed('affiliate'))
+ array_push($this->associated_DELETE,array('table'=>'affiliate','field'=>'account_id'));
+
+ $result = parent::delete($VAR);
+
+ if ($result) {
+ # Generate the full query (invoice)
+ $invoice = $db->Execute(sqlSelect($db,'invoice','id',array('account_id'=>$ids)));
+ if ($invoice && $invoice->RecordCount() > 0 ) {
+ while (! $invoice->EOF) {
+ include_once(PATH_MODULES.'invoice/invoice.inc.php');
+ $inv = new invoice;
+
+ $arr['id'] = $invoice->fields['id'];
+ $inv->delete($arr,$inv);
+
+ $invoice->MoveNext();
+ }
+ }
+
+ # Error reporting
+ if ($result === false) {
+ global $C_debug;
+ $C_debug->error('account_admin.inc.php','delete', $db->ErrorMsg());
+
+ } else {
+ # Alert delete message
+ global $C_debug, $C_translate;
+ $C_translate->value['CORE']['module_name'] = $C_translate->translate('name',$this->table,'');
+ $message = $C_translate->translate('alert_delete_ids','CORE','');
+ $C_debug->alert($message);
+ }
}
- else
- {
- ### Or if no results:
- $smarty->assign('show_static_var', false);
+ }
+
+ /**
+ * Update account groups
+ *
+ * This method is a trigger, called when an account is added from account()
+ *
+ * @uses CORE_validate
+ */
+ public function update_account_groups($VAR) {
+ global $C_auth;
+
+ $db = &DB();
+ @$account = $VAR['account_id'];
+
+ # If there are no groups to modify, just return
+ if (! is_array($VAR['groups']) || ! count($VAR['groups']))
return false;
+
+ $groups = $VAR['groups'];
+
+ # Admin accounts groups cannot be altered user cannot modify their own groups
+ if ($account == '1' || SESS_ACCOUNT == $account)
+ return false;
+
+ # Drop the current groups for this account
+ $result = $db->Execute(sqlDelete($db,'account_group',sprintf('service_id IS NULL AND account_id=%s',$account)));
+
+ # Verify the admin adding this account is authorized for this group themselves, otherwise skip
+ foreach ($groups as $i => $group)
+ if (! $C_auth->auth_group_by_id($groups[$i]))
+ unset($groups[$i]);
+
+ if (! count($group))
+ return false;
+
+ # Determine the expiration
+ if (! empty($VAR['account_date_expire'])) {
+ include_once(PATH_CORE.'validate.inc.php');
+ $validate = new CORE_validate;
+
+ $expire = $validate->convert_date($VAR['account_date_expire'],DEFAULT_DATE_FORMAT);
+ } else {
+ $expire = 0;
+ }
+
+ $this->add_account_groups($groups,$account,$expire);
+
+ # Remove the user's session_auth_cache so it is regenerated on user's next pageview
+ $rss = $db->Execute(sqlSelect($db,'session','id',array('account_id'=>$account)));
+
+ while (! $rss->EOF) {
+ $db->Execute(sqlDelete($db,'session_auth_cache',sprintf('session_id=::%s::',$rss->fields['id'])));
+ $rss->MoveNext();
}
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/account/account_construct.xml b/modules/account/account_construct.xml
index bd59606a..8898a760 100644
--- a/modules/account/account_construct.xml
+++ b/modules/account/account_construct.xml
@@ -1,193 +1,309 @@
-
- account
-
-
-
-
-
- 0
-
- last_name
-
- 30
-
-
-
- I8
- 1
-
-
- I4
-
-
- I8
-
-
- I8
- date-now
-
-
- I8
- date
-
-
- I4
-
-
- C(32)
-
-
- I4
-
-
- C(32)
-
-
- I4
-
-
- I4
-
-
- I4
-
-
- C(32)
-
-
- C(128)
- 4
- 12
- any
- 1
- 1
-
-
- C(128)
- 6
- 12
- password
- md5
-
-
- L
-
-
- C2(128)
-
-
- I4
-
-
- C(128)
- 1
- 128
- any
- 1
-
-
- C(128)
-
-
- C(128)
- 1
- 128
- any
- 1
-
-
- C(128)
-
-
- C(255)
- 4
- 128
- email
- 1
- 1
-
-
- C(255)
-
-
- C(128)
- 3
- 128
- any
-
-
- C(128)
- 128
-
-
- C(32)
- 2
- 32
- any
-
-
- C(32)
- 2
- 32
- any
-
-
- C(16)
- 4
- 16
- any
-
-
- L
-
-
- I4
-
-
- L
- 1
-
-
- I4
-
-
- I4
-
-
- C(64)
-
-
- I4
-
-
-
-
- username,password
- first_name,middle_name,last_name
- company
- email
- affiliate_id
- campaign_id
- country_id
- city,state
- city
- state
- zip
- id,site_id
- first_name,last_name,email,company
-
-
-
- id,date_orig,date_last,language_id,country_id,affiliate_id,reseller_id,currency_id,theme_id,username,password,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
- id,date_orig,date_last,language_id,country_id,affiliate_id,reseller_id,currency_id,theme_id,username,password,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,email_type,tax_id
- id,parent_id,date_last,language_id,country_id,affiliate_id,reseller_id,currency_id,theme_id,username,password,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,email_type,tax_id,max_child
-
-
-
-
- account_admin:add_account_groups
-
-
+
+ account
+
+
+
+
+
+ 0
+
+ last_name
+
+ 25
+
+ 1
+
+
+
+ username,password
+ first_name,middle_name,last_name
+ company
+ email
+ affiliate_id
+ campaign_id
+ country_id
+ city,state
+ city
+ state
+ zip
+ id,site_id
+ first_name,last_name,email,company
+
+
+
+
+
+
+ 1
+ I8
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ date-now
+ Date Updated
+ I8
+
+
+ I8
+ date
+ Date Expire
+
+
+ I4
+ Parent Account
+
+
+ C(32)
+ Language
+
+
+ I4
+ Country
+
+
+ I4
+
+
+ I4
+
+
+ I4
+
+
+ I4
+ Currency
+
+
+ C(32)
+ Theme
+
+
+ C(128)
+ 4
+ 128
+ any
+ 1
+ 1
+ User Name
+
+
+ C(128)
+ 6
+ 128
+ password
+ md5
+ Password
+
+
+ L
+
+
+
+ C2(128)
+
+
+
+ Active
+ I4
+
+
+ C(128)
+ 1
+ 128
+ any
+ 1
+ First Name
+
+
+ C(128)
+ Middle Name
+
+
+ C(128)
+ 1
+ 128
+ any
+ 1
+ Last Name
+
+
+ C(128)
+ Title
+
+
+ C(255)
+ 4
+ 128
+ email
+ 1
+ 1
+ Email
+
+
+ C(255)
+ Company
+
+
+ C(128)
+ 3
+ 128
+ any
+ Address
+
+
+ C(128)
+ 128
+ Address
+
+
+ C(32)
+ 2
+ 32
+ any
+ City
+
+
+ C(32)
+ 2
+ 32
+ any
+ State
+
+
+ C(16)
+ 4
+ 16
+ any
+ Postal Code
+
+
+ L
+ HTML Email
+
+
+ I4
+ Invoice Delivery
+
+
+ L
+ 1
+ Show Itemised Invoice
+
+
+ I4
+ Invoice Grace Period
+
+
+ I4
+ Invoice Advance Generation
+
+
+ C(64)
+ Tax ID
+
+
+ I4
+ Max Children
+
+
+
+ I4
+ Net Terms
+
+
+
+
+
+ date_orig,date_last,language_id,country_id,affiliate_id,reseller_id,campaign_id,currency_id,theme_id,username,password,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,email_type,tax_id,invoice_delivery,invoice_show_itemized,invoice_grace
+ id,date_orig,date_last,language_id,country_id,affiliate_id,reseller_id,currency_id,theme_id,username,password,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,email_type,tax_id
+ id,parent_id,date_last,language_id,country_id,affiliate_id,reseller_id,currency_id,theme_id,username,password,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,email_type,tax_id,max_child
+ id
+ search,date_expire,language_id,country_id,currency_id,theme_id,username,password,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip
+ id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child
+ id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child
+ id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child
+ id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,tax_id,max_child
+ language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
+ language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
+ language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
+ language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
+
+
+
+
+
+ account:add_account_groups
+
+
+ account:update_account_groups
+
+
+
+
+
+ Register User Account
+ Send Email to User
+ Merge User Accounts
+ Search
+ Register User Account
+ Update User Account
+ Reset Password
+ Reset Password
+ Enter Verification Code
+ Resend Verification Email
+ Account
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ status
+ bool_icon
+ 20px
+
+
+ last_name
+
+
+ first_name
+
+
+ username
+ 25
+
+
+ email
+ 25
+
+
+ literal
+ 120px
+
+
+
+
+]]>
+
+
+
diff --git a/modules/account/account_install.xml b/modules/account/account_install.xml
index c664002c..712518bb 100644
--- a/modules/account/account_install.xml
+++ b/modules/account/account_install.xml
@@ -1,14 +1,101 @@
+
+
+
+
+
+ Account
+
+ 1
+
account
- account
-
+
+
+
+
+
+
+
+ base
-
-
-
- install
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ Search
+ 1
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+ search_export
+
+
+ install
+
+
+ update_account_groups
+
+
+
+ send_verify_email
+
+
+
+ send_password_email
+
+
+
+ mail_multi
+
+
+ mail_one
+
+
+ autoselect
+
+
+ login
+
+
+
+ merge
+
+
+ group_search
+
+
+ product_search
+
+
+
diff --git a/modules/account/account_install_data.xml b/modules/account/account_install_data.xml
index 26e597a8..751480ae 100644
--- a/modules/account/account_install_data.xml
+++ b/modules/account/account_install_data.xml
@@ -1,33 +1,33 @@
-
- 1
- 1
- 1075175744
- 1112335769
- 0
- 0
- english
- 840
- 0
- 1
- default
- admin
- 21232f297a57a5a743894a0e4a801fc3
- Notes
- 1
- Admin
- Admin
- Mrs
- email@company.com
-
- City
- State
- 12345
- 0
- 0
-
-
- 33
-
-
\ No newline at end of file
+
+ 1
+ 1
+ 1075175744
+ 1112335769
+ 0
+ 0
+ english
+ 840
+ 0
+ 1
+ default
+ admin
+ 21232f297a57a5a743894a0e4a801fc3
+ Notes
+ 1
+ Admin
+ Admin
+ Mrs
+ email@company.com
+
+ City
+ State
+ 12345
+ 0
+ 0
+
+
+ 33
+
+
diff --git a/modules/account/auth.inc.php b/modules/account/auth.inc.php
index c637b6b8..098fc3a9 100644
--- a/modules/account/auth.inc.php
+++ b/modules/account/auth.inc.php
@@ -1,38 +1,37 @@
-
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Modules:Account
*/
-$auth_methods = Array
-(
- Array ('module' => 'account', 'method' => 'add'),
- Array ('module' => 'account', 'method' => 'user_add'),
- Array ('module' => 'account', 'method' => 'user_view'),
- Array ('module' => 'account', 'method' => 'add'),
- Array ('module' => 'account', 'method' => 'view'),
- Array ('module' => 'account', 'method' => 'update'),
- Array ('module' => 'account', 'method' => 'password'),
- Array ('module' => 'account', 'method' => 'password_reset'),
- Array ('module' => 'account', 'method' => 'static_var'),
- Array ('module' => 'account', 'method' => 'verify'),
- Array ('module' => 'account', 'method' => 'verify_resend'),
- Array ('module' => 'account', 'method' => 'sub_account_add'),
- Array ('module' => 'account', 'method' => 'sub_delete')
-);
+/**
+ * Public Account methods
+ */
-?>
\ No newline at end of file
+$auth_methods = array(
+ array('module'=>'account','method'=>'user_add'),
+ array('module'=>'account','method'=>'user_view'),
+ array('module'=>'account','method'=>'user_password'),
+ array('module'=>'account','method'=>'user_password_reset'),
+ array('module'=>'account','method'=>'user_verify'),
+ array('module'=>'account','method'=>'user_verify_resend')
+);
+?>
diff --git a/modules/account_admin/account_admin.inc.php b/modules/account_admin/account_admin.inc.php
deleted file mode 100644
index 13ecc29c..00000000
--- a/modules/account_admin/account_admin.inc.php
+++ /dev/null
@@ -1,2651 +0,0 @@
-
- * @package AgileBill
- * @version 1.4.93
- */
-
-class account_admin
-{
-
- # Open the constructor for this mod
- function account_admin()
- {
- # name of this module:
- $this->module = "account_admin";
-
- if(!defined('AJAX'))
- {
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
- }
-
- /**
- * Check account limitations
- */
- function checkLimits() {
- if(!defined('AGILE_RST_ACCOUNT') || AGILE_RST_ACCOUNT <= 0) return true;
- $sql="SELECT count(*) as totalacct from ".AGILE_DB_PREFIX."account WHERE site_id=".DEFAULT_SITE;
- $db=&DB();
- $rs=$db->Execute($sql);
- if($rs && $rs->RecordCount() && $rs->fields['totalacct'] <= AGILE_RST_ACCOUNT) {
- return true;
- } else {
- echo "Licensed user limit of ".AGILE_RST_ACCOUNT." exceeded, operation failed.";
- return false;
- }
- return true;
- }
-
- /* BEGIN: custom product/group searching method */
-
- function group_search($VAR) {
- $sql = '';
- echo "";
-
- // get date ranges:
- foreach($VAR['dates']['val'] as $cond => $val)
- {
- if($val > 0) {
- $exp = $VAR['dates']['expr'][$cond];
- $val = $this->convert_date($val,false);
-
- if(!empty($sql)) $sql .= " AND "; else $sql = " ";
- $sql .= " A.date_orig $exp $val ";
- }
- }
- if(!empty($sql)) $sql = " ( $sql ) ";
-
- // get group(s)
- if(!empty($VAR['groups'])) {
- foreach($VAR['groups'] as $group )
- {
- if($group != 0) {
- if(!empty($sql2)) $sql2 .= " OR "; else $sql2 = " ";
- $sql2 .= " B.group_id = $group ";
- }
- }
- }
- if(!empty($sql2)) {
- if(!empty($sql)) $sql .= " AND \r\n";
- $sql .= " ( $sql2 ) AND ( A.id = B.account_id AND B.active = 1 ) ";
- }
-
- // Assemble SQL:
- $q = "SELECT DISTINCT A.* FROM
- ". AGILE_DB_PREFIX ."account as A,
- ". AGILE_DB_PREFIX ."account_group as B
- WHERE (
- A.site_id = ". DEFAULT_SITE ." AND
- B.site_id = ". DEFAULT_SITE ." ) ";
- if(!empty($sql)) $q .= " AND " . $sql;
- $db = &DB();
- $rs = $db->Execute($q);
-
- // print results in text format
- if($rs && $rs->RecordCount() > 0) {
- while(!$rs->EOF) {
- echo $rs->fields['first_name'] .', '.$rs->fields['last_name'] .', '.$rs->fields['email'] .', '.$rs->fields['company'] .",\r\n";
- $rs->MoveNext();
- }
- } else {
- echo "No matches !";
- }
- echo " ";
- }
-
-
-
- function product_search($VAR) {
- $sql = '';
- echo "";
-
- // get date ranges:
- if(!empty($VAR["dates"]))
- {
- foreach($VAR['dates']['val'] as $cond => $val)
- {
- if($val > 0) {
- $exp = $VAR['dates']['expr'][$cond];
- $val = $this->convert_date($val,false);
-
- if(!empty($sql)) $sql .= " AND "; else $sql = " ";
- $sql .= " B.date_orig $exp $val ";
- }
- }
- }
- if(!empty($sql)) $sql = " ( $sql ) ";
-
- // get group(s)
- if(!empty($VAR['products'])) {
- foreach($VAR['products'] as $prod )
- {
- if($prod != 0) {
- if(!empty($sql2)) $sql2 .= " OR "; else $sql2 = " ";
- $sql2 .= " B.product_id = $prod ";
- }
- }
- }
- if(!empty($sql2)) {
- if(!empty($sql)) $sql .= " AND \r\n";
- $sql .= " ( $sql2 ) AND ( A.id = C.account_id AND C.id = B.invoice_id ) ";
- }
-
- // Assemble SQL:
- $q = "SELECT DISTINCT A.* FROM
- ". AGILE_DB_PREFIX ."account as A,
- ". AGILE_DB_PREFIX ."invoice_item as B,
- ". AGILE_DB_PREFIX ."invoice as C
- WHERE (
- A.site_id = ". DEFAULT_SITE ." AND
- C.site_id = ". DEFAULT_SITE ." AND
- B.site_id = ". DEFAULT_SITE ." ) ";
- if(!empty($sql)) $q .= " AND " . $sql;
- $db = &DB();
- $rs = $db->Execute($q);
-
-
- // print results in text format
- if($rs && $rs->RecordCount() > 0) {
- while(!$rs->EOF) {
- echo $rs->fields['first_name'] .', '.$rs->fields['last_name'] .', '.$rs->fields['email'] .', '.$rs->fields['company'] .",\r\n";
- $rs->MoveNext();
- }
- } else {
- echo "No matches !";
- }
- echo " ";
- }
-
- function convert_date ($date,$field)
- {
- if($date == '0' || $date == '')
- return '';
-
- $Arr_format = explode(DEFAULT_DATE_DIVIDER, UNIX_DATE_FORMAT);
- $Arr_date = explode(DEFAULT_DATE_DIVIDER, $date);
-
- for($i=0; $i<3; $i++)
- {
- if($Arr_format[$i] == 'd')
- $day = $Arr_date[$i];
-
- if($Arr_format[$i] == 'm')
- $month = $Arr_date[$i];
-
- if($Arr_format[$i] == 'Y')
- $year = $Arr_date[$i];
- }
-
- $timestamp = mktime(0, 0, 0, $month, $day, $year);
- return $timestamp;
- }
-
- /* END: custom product/group searching method */
-
-
-
-
-
-
-
-
- ###########################################
- ### AJAX Auto-selector
- ###########################################
-
- function autoselect($VAR)
- {
- if(!$this->checkLimits()) return false; // check account limits
-
- $db = &DB();
- $p = AGILE_DB_PREFIX;
-
- if (empty($VAR['account_search'])) {
- $where = "id > 0";
- $type = 1;
- } elseif (is_numeric($VAR['account_search'])) {
- $where = "id LIKE ".$db->qstr($VAR['account_search']."%");
- $type = 1;
- } elseif (eregi(" ", $VAR['account_search'])) {
- $arr = explode(" ", $VAR['account_search']);
- $where = "first_name = ".$db->qstr($arr[0])." AND ".
- "last_name LIKE ".$db->qstr($arr[1].'%') ;
- $type = 2;
- } elseif (eregi("@", $VAR['account_search'])) {
- $where = "email LIKE ".$db->qstr('%'.$VAR['account_search'].'%') ;
- $type = 3;
-
- } else {
- $where = "username LIKE ".$db->qstr($VAR['account_search'].'%')." OR ".
- "first_name LIKE ".$db->qstr($VAR['account_search'].'%')." OR ".
- "last_name LIKE ".$db->qstr($VAR['account_search'].'%') ;
- $type = 4;
- }
-
- $q = "SELECT id,email,first_name,last_name,username FROM {$p}account WHERE
- ( $where )
- AND
- site_id = " . DEFAULT_SITE."
- ORDER BY first_name,last_name";
- $result = $db->SelectLimit($q,10);
-
- # Create the alert for no records found
- echo '';
- # Create the alert for no records found
- if ($result->RecordCount() > 0) {
- $i=0;
- while(!$result->EOF)
- {
- echo '' . $result->fields['first_name'].' '.$result->fields['last_name'] . '
'.
- ''.$result->fields['email']. '
'.
- ''.$result->fields['id']. '
' . "\r\n";
- $result->MoveNext();
- $i++;
- }
- }
- echo " ";
-
- }
-
-
- ###########################################
- ### Login as user
- ###########################################
-
- function login($VAR)
- {
- global $C_auth;
-
- # Check for target user
- $display_this=false;
- if(!empty($VAR['account_id']))
- {
- ### Get any authorized groups of the target account
- $dba = &DB();
- $sql = 'SELECT group_id FROM ' . AGILE_DB_PREFIX . 'account_group WHERE
- site_id = ' . $dba->qstr(DEFAULT_SITE) . ' AND
- account_id = ' . $dba->qstr($VAR['account_id']) . ' AND
- active = ' . $dba->qstr("1") . '
- ORDER BY group_id';
- $groups = $dba->Execute($sql);
- while (!$groups->EOF) {
- $group[] = $groups->fields['group_id'];
- $groups->MoveNext();
- }
-
- ### Verify the user has access to view this account:
- if(SESS_ACCOUNT != $VAR['account_id']) {
- $display_this = true;
- for($ix=0; $ixauth_group_by_id($group[$ix]))
- $display_this = false;
- }
- } else {
- return false;
- }
-
- } else {
- return false;
- }
-
- # Logout current user and login as the target user
- if($display_this)
- {
- $db = &DB();
- $sql = 'SELECT username,password FROM ' . AGILE_DB_PREFIX . 'account WHERE
- site_id = ' . $dba->qstr(DEFAULT_SITE) . ' AND
- id = ' . $dba->qstr($VAR['account_id']);
- $acct = $db->Execute($sql);
- $arr['_username'] = $acct->fields['username'];
- $arr['_password'] = $acct->fields['password'];
- include_once(PATH_CORE.'login.inc.php');
- $login = new CORE_login_handler;
- $login->logout($VAR);
- $login->login($arr, $md5=false);
- define('REDIRECT_PAGE', '?_page=account:account&tid='.DEFAULT_THEME);
- }
-
-
- ####################################################################
- ### Do any db_mapping
- ####################################################################
- $db = &DB();
- $sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'module WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- name = ' . $db->qstr('db_mapping') . ' AND
- status = ' . $db->qstr("1");
- $result = $db->Execute($sql);
- if($result->RecordCount() > 0)
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- $db_map->login ( $VAR['account_id'] );
- }
- }
-
-
- ###########################################
- ### Account selector list search
- ###########################################
-
- function popup_search($VAR)
- {
- $db = &DB();
- if (empty($VAR['search'])) {
- $where = '';
- } elseif (eregi(" ", $VAR['search'])) {
- $arr = explode(" ", $VAR['search']);
- $where = "first_name = ".$db->qstr($arr[0])." AND ".
- "last_name LIKE ".$db->qstr('%'.$arr[1].'%')." AND ";
- } else {
- $where = "username LIKE ".$db->qstr('%'.$VAR['search'].'%')." OR ".
- "first_name LIKE ".$db->qstr('%'.$VAR['search'].'%')." OR ".
- "first_name LIKE ".$db->qstr('%'.$VAR['search'].'%')." OR ".
- "company LIKE ". $db->qstr('%'.$VAR['search'].'%')." AND ";
- }
-
- $q = "SELECT id,first_name,last_name
- FROM ".AGILE_DB_PREFIX."account
- WHERE $where
- site_id = '" . DEFAULT_SITE . "'";
-
- $q_save = "SELECT * FROM ".AGILE_DB_PREFIX."account WHERE $where %%whereList%% ";
- $result = $db->Execute($q);
-
- /// DEBUG ////
- // echo "$q ";
-
- # get the result count:
- $results = $result->RecordCount();
-
- # Create the alert for no records found
- if ($results == 0)
- {
- $id = $result->fields['id'];
- $name = $result->fields['first_name'].' '.$result->fields['last_name'];
- $val = $id.'|'.$name;
- $res = '
- ';
- echo $res;
- }
- else if ($results == 1)
- {
- $id = $result->fields['id'];
- $name = $result->fields['first_name'].' '.$result->fields['last_name'];
- $val = $id.'|'.$name;
- $res = '
- ';
- echo $res;
- }
- else
- {
- # create the search record
- include_once(PATH_CORE . 'search.inc.php');
- $search = new CORE_search;
- $arr['module'] = $this->module;
- $arr['sql'] = $q_save;
- $arr['limit'] = '30';
- $arr['order_by'] = 'last_name';
- $arr['results'] = $results;
- $search->add($arr);
-
- global $smarty;
- $smarty->assign('search_id', $search->id);
- $smarty->assign('page', '1');
- $smarty->assign('limit', $limit);
- $smarty->assign('order_by', $order_by);
- $smarty->assign('results', $results);
-
- $res = '
- ';
-
- echo $res;
-
- }
- }
-
-
- ###########################################
- ### Top Accounts Graph:
- ###########################################
- function top($VAR)
- {
- global $smarty, $C_translate, $C_auth;
-
- # Get the period type, default to month
- if (empty($VAR['period']))
- $p = 'm';
- else
- $p = $VAR['period'];
-
- # Load the jpgraph class
- include (PATH_GRAPH."jpgraph.php");
- include (PATH_GRAPH."jpgraph_bar.php");
-
- # check the validation for this function
- if(!$C_auth->auth_method_by_name($this->module,'search')) {
- $error = $C_translate->translate('module_non_auth','','');
- include (PATH_GRAPH."jpgraph_canvas.php");
- $graph = new CanvasGraph(460,55,"auto");
- $t1 = new Text($error);
- $t1->Pos(0.2,0.5);
- $t1->SetOrientation("h");
- $t1->SetBox("white","black",'gray');
- $t1->SetFont(FF_FONT1,FS_NORMAL);
- $t1->SetColor("black");
- $graph->AddText($t1);
- $graph->Stroke();
- exit;
- }
-
- # Get the period start & end
- switch ($p)
- {
- # By Weeks:
- case 'w':
- $interval = "1";
- $width = ".9";
- $title = 'Top Accounts for Last Last Week';
- $dow = date('w');
- $start_str = mktime(0,0,0,date('m'), date('d')-$dow, date('y'));
- $end_str = mktime(23,59,59,date('m'), date('d'), date('y'));
- break;
-
- # By Months:
- case 'm':
- $interval = "3";
- $width = ".6";
- $title = 'Top Accounts for Last Last Month';
- $start_str = mktime(0,0,0,date('m'), 1, date('y'));
- $end_str = mktime(23,59,59,date('m'), date('d'), date('y'));
- break;
-
- # By Years:
- case 'y':
- $interval = "1";
- $width = ".8";
- $title = 'Top Accounts for Last Last Year';
- $start_str = mktime(0,0,0,1,1, date('y'));
- $end_str = mktime(23,59,59, date('m'), date('d'), date('y'));
- break;
- }
-
-
- ##############################@@@@@@@@
- # Get accounts & sales for this period
- ##############################@@@@@@@@
- $db = &DB();
- $sql = 'SELECT account_id,total_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- date_orig >= ' . $db->qstr( $start_str ) . ' AND date_orig <= ' . $db->qstr( $end_str ) . ' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
- if(@$result->RecordCount() == 0) {
- $file = fopen( PATH_THEMES.'default_admin/images/invisible.gif', 'r');
- fpassthru($file);
- exit;
- }
-
- while(!$result->EOF)
- {
- $amt = $result->fields['total_amt'];
- $acct = $result->fields['account_id'];
- if(!isset( $arr[$acct] )) $arr[$acct] = 0;
- $arr[$acct] += $amt;
- $result->MoveNext();
- }
-
- $i = 0;
- while(list($key, $var) = each(@$arr)) {
- # Get the user name
- $sql = 'SELECT first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account WHERE
- id = ' . $db->qstr( $key ) . ' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $rs = $db->Execute($sql);
-
- $_lbl[] = strtoupper(substr($rs->fields['first_name'],0,1)) . ". " . $rs->fields['last_name'];
- $_datay[] = $var;
- $i++;
- }
-
-
- ### Sort the arrays
- array_multisort($_datay,SORT_DESC, SORT_NUMERIC, $_lbl);
-
- ### Limit the results to 10 or less
- for($i=0; $i=9) $i = count($_lbl);
- }
-
- $i = count($lbl);
-
-
- # Get the Currency
- $sql = 'SELECT symbol FROM ' . AGILE_DB_PREFIX . 'currency WHERE
- id = ' . $db->qstr( DEFAULT_CURRENCY ) . ' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $rs = $db->Execute($sql);
- $currency_iso = $rs->fields['symbol'];
-
- // Size of graph
- $width=265;
- $height=75 + ($i*15);
-
- // Set the basic parameters of the graph
- $graph = new Graph($width,$height,'auto');
- $graph->SetScale("textlin");
- $graph->yaxis->scale->SetGrace(50);
- $graph->SetMarginColor('#F9F9F9');
- $graph->SetFrame(true,'#CCCCCC',1);
- $graph->SetColor('#FFFFFF');
-
- $top = 45;
- $bottom = 10;
- $left = 95;
- $right = 15;
- $graph->Set90AndMargin($left,$right,$top,$bottom);
-
- // Label align for X-axis
- $graph->xaxis->SetLabelAlign('right','center','right');
-
- // Label align for Y-axis
- $graph->yaxis->SetLabelAlign('center','bottom');
- $graph->xaxis->SetTickLabels($lbl);
-
- // Titles
- $graph->title->SetFont(FF_FONT1,FS_BOLD,9.5);
- $title = $C_translate->translate('graph_top','account_admin','');
- $graph->title->Set($title);
-
- // Create a bar pot
- $bplot = new BarPlot($datay);
- $bplot->SetFillColor("#506DC7");
- $bplot->SetWidth(0.2);
-
- // Show the values
- $bplot->value->Show();
- $bplot->value->SetFont(FF_FONT1,FS_NORMAL,8);
- $bplot->value->SetAlign('center','center');
- $bplot->value->SetColor("black","darkred");
- $bplot->value->SetFormat($currency_iso.'%.2f');
-
- $graph->Add($bplot);
- $graph->Stroke();
-
- return;
- }
-
-
-
- ##############################
- ## MAIL ONE ACCOUNT ##
- ##############################
- function mail_one($VAR)
- {
- global $C_translate, $C_debug;
-
- ## Validate the required vars (account_id, message, subject)
- if(@$VAR['mail_account_id'] != "" && @$VAR['mail_subject'] != "" && @$VAR['mail_message'] != "")
- {
- ## Verify the specified account:
- $db = &DB();
- $sql = 'SELECT email,first_name,last_name FROM ' . AGILE_DB_PREFIX . 'account WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($VAR['mail_account_id']);
- $account = $db->Execute($sql);
-
- if($account->RecordCount() == 0)
- {
- ## Error message:
- $C_debug->alert($C_translate->translate('account_non_exist','account_admin',''));
- return;
- }
-
- ################################################################
- ## OK to send the email:
-
- $db = &DB();
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."setup_email WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- id = ".$db->qstr($VAR['mail_email_id']);
- $setup_email = $db->Execute($q);
-
- $E['priority'] = $VAR['mail_priority'];
- $E['html'] = '0';
- $E['subject'] = $VAR['mail_subject'];
- $E['body_text'] = $VAR['mail_message'];
- $E['to_email'] = $account->fields['email'];
- $E['to_name'] = $account->fields['first_name'] . ' ' . $account->fields['last_name'];
-
-
- if($setup_email->fields['type'] == 0)
- {
- $type = 0;
- }
- else
- {
- $type = 1;
- $E['server'] = $setup_email->fields['server'];
- $E['account'] = $setup_email->fields['username'];
- $E['password'] = $setup_email->fields['password'];
- }
-
- $E['from_name'] = $setup_email->fields['from_name'];
- $E['from_email'] = $setup_email->fields['from_email'];
-
- if($setup_email->fields['cc_list'] != '')
- $E['cc_list'] = explode(',', $setup_email->fields['cc_list']);
-
- if($setup_email->fields['bcc_list'] != '')
- $E['bcc_list'] = explode(',', $setup_email->fields['bcc_list']);
-
-
- ### Call the mail class
- require_once(PATH_CORE . 'email.inc.php');
- $email = new CORE_email;
- if($type == 0)
- $email->PHP_Mail($E);
- else
- $email->SMTP_Mail($E);
-
-
- }
- else
- {
- ## Error message:
- $C_debug->alert($C_translate->translate('validate_any','',''));
-
- ## Stripslashes
- global $C_vars;
- $C_vars->strip_slashes_all();
- return;
- }
-
- ## Success message:
- $C_debug->alert($C_translate->translate('mail_sent','account_admin',''));
-
- ## Stripslashes
- global $C_vars;
- $C_vars->strip_slashes_all();
- }
-
-
- ##############################
- ## MAIL MULTI ACCOUNTS ##
- ##############################
- function mail_multi($VAR)
- {
- if(!$this->checkLimits()) return false; // check account limits
-
- global $C_translate, $C_debug;
-
- ## Validate the required vars (account_id, message, subject)
- if(@$VAR['search_id'] != "" && @$VAR['mail_subject'] != "" && @$VAR['mail_message'] != "")
- {
-
- ## Get the specified accounts:
- # get the search details:
- if(isset($VAR['search_id'])) {
- include_once(PATH_CORE . 'search.inc.php');
- $search = new CORE_search;
- $search->get($VAR['search_id']);
- } else {
- # invalid search!
- echo ' The search terms submitted were invalid!'; # translate... # alert
- return;
- }
-
- # generate the full query
- $field_list = AGILE_DB_PREFIX."account.email, ".
- AGILE_DB_PREFIX."account.first_name, ".
- AGILE_DB_PREFIX."account.last_name ";
-
- $q = eregi_replace("%%fieldList%%", $field_list, $search->sql);
- $q = eregi_replace("%%tableList%%", AGILE_DB_PREFIX."account", $q);
- $q = eregi_replace("%%whereList%%", "", $q);
- $q .= " ".AGILE_DB_PREFIX."account.site_id = '" . DEFAULT_SITE . "'";
- $db = &DB();
- $account = $db->Execute($q);
-
- // check results
- if($account->RecordCount() == 0) {
- $C_debug->alert($C_translate->translate('account_non_exist','account_admin',''));
- return;
- }
-
- // get the selected email setup details
- $db = &DB();
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."setup_email WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- id = ".$db->qstr($VAR['mail_email_id']);
- $setup_email = $db->Execute($q);
- if($setup_email->fields['type'] == 0) {
- $type = 0;
- } else {
- $type = 1;
- $E['server'] = $setup_email->fields['server'];
- $E['account'] = $setup_email->fields['username'];
- $E['password'] = $setup_email->fields['password'];
- }
-
- // loop to send each e-mail
- while ( !$account->EOF )
- {
- $E['priority'] = $VAR['mail_priority'];
- $E['html'] = '0';
- $E['subject'] = $VAR['mail_subject'];
- $E['body_text'] = $VAR['mail_message'];
- $E['to_email'] = $account->fields['email'];
- $E['to_name'] = $account->fields['first_name'] . ' ' . $account->fields['last_name'];
- $E['from_name'] = $setup_email->fields['from_name'];
- $E['from_email'] = $setup_email->fields['from_email'];
-
- ### Call the mail class
- require_once(PATH_CORE . 'email.inc.php');
- $email = new CORE_email;
- $email = new CORE_email;
- if($type == 0)
- $email->PHP_Mail($E);
- else
- $email->SMTP_Mail($E);
-
- ### Next record
- $account->MoveNext();
- }
-
-
- } else {
- ## Error message:
- $C_debug->alert($C_translate->translate('validate_any','',''));
-
- ## Stripslashes
- global $C_vars;
- $C_vars->strip_slashes_all();
- return;
- }
-
- ## Success message:
- $C_debug->alert($C_translate->translate('mail_sent','account_admin',''));
-
- ## Stripslashes
- global $C_vars;
- $C_vars->strip_slashes_all();
- }
-
-
- ##############################
- ## SEND PASSWORD CHANGE ##
- ##############################
- function send_password_email($VAR)
- {
- global $C_translate, $C_debug;
- require_once(PATH_MODULES . 'email_template/email_template.inc.php');
- $my = new email_template;
- $my->send('password_change_instructions', @$VAR['id'], '', '', '');
- echo $C_translate->translate("password_change_instructions","account_admin","");
- }
-
-
- ##############################
- ## SEND VERIFY E-MAIL ##
- ##############################
- function send_verify_email($VAR)
- {
- global $C_translate, $C_debug;
-
- require_once(PATH_MODULES . 'email_template/email_template.inc.php');
- $my = new email_template;
- $db = &DB();
- $dbm = new CORE_database;
- echo $sql = $dbm->sql_select('account','date_orig',"id = {$VAR['id']}",'', $db);
- $result = $db->Execute($sql);
- $validation_str = strtoupper($result->fields['date_orig']. ':' . $VAR['id']);
- $my->send('account_registration_inactive', @$VAR['id'], @$VAR['id'], '', $validation_str);
- echo $C_translate->translate("account_verify_instructions","account_admin","");
- }
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- if(!$this->checkLimits()) return false; // check account limits
-
- global $C_translate, $C_debug, $smarty;
-
- ### Set the hidden values:
- $VAR['account_admin_date_orig'] = time();
- $VAR['account_admin_date_last'] = time();
- if(!empty($VAR["account_admin_date_expire"])) {
- include_once(PATH_CORE.'validate.inc.php');
- $val = new CORE_validate;
- $date_expire = $val->DateToEpoch(false, $VAR["account_admin_date_expire"]);
- } else {
- $date_expire = 0;
- }
-
-
- ### Determine the proper account status:
- if(!isset($VAR['account_admin_status']) || $VAR['account_admin_status'] != "1")
- $status = 0;
- else
- $status = 1;
-
-
- ### DEFINE A USERNAME:
- if(empty($VAR['account_admin_username'])) {
- $length = 4;
- srand((double)microtime()*1000000);
- $vowels = array("a", "e", "i", "o", "u");
- $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p",
- "r", "s", "t", "u", "v", "w", "tr", "cr", "br", "fr", "th",
- "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl");
- $num_vowels = count($vowels);
- $num_cons = count($cons);
- for($i = 0; $i < $length; $i++){
- @$VAR['account_admin_username'] .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
- }
- }
-
- ## Single field login:
- if(defined('SINGLE_FIELD_LOGIN') && SINGLE_FIELD_LOGIN==true && empty($VAR['account_admin_password'])) {
- $VAR['account_admin_password']='none';
- $passwd = 'none';
- }
-
- ### DEFINE A PASSWORD:
- if(empty($VAR['account_admin_password']))
- {
- srand((double)microtime() * 1000000);
- $UniqID = md5(uniqid(rand()));
- @$VAR['account_admin_password'] = substr(md5(uniqid(rand())), 0, 10);
- $passwd = '********';
- } else {
- $passwd = $VAR['account_admin_password'];
-
- /* hash the password */
- if(defined('PASSWORD_ENCODING_SHA'))
- $VAR['account_admin_password'] = sha1($VAR['account_admin_password']);
- else
- $VAR['account_admin_password'] = md5($VAR['account_admin_password']);
- }
-
-
- ####################################################################
- ### loop through the field list to validate the required fields
- ####################################################################
-
- $type = 'add';
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $arr = $this->method["$type"];
- include_once(PATH_CORE . 'validate.inc.php');
- $validate = new CORE_validate;
- $this->validated = true;
-
- while (list ($key, $value) = each ($arr))
- {
- # get the field value
- $field_var = $this->module . '_' . $value;
- $field_name = $value;
-
- ####################################################################
- ### perform any field validation...
- ####################################################################
-
- # check if this value is unique
- if(isset($this->field["$value"]["unique"]) && isset($VAR["$field_var"]))
- {
- if(!$validate->validate_unique($this->table, $field_name, "record_id", $VAR["$field_var"]))
- {
- $this->validated = false;
- $this->val_error[] = array('field' => $this->table . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $this->module, ""), # translate
- 'error' => $C_translate->translate('validate_unique',"", ""));
- }
- }
-
- # check if the submitted value meets the specifed requirements
- if(isset($this->field["$value"]["validate"]))
- {
- if(isset($VAR["$field_var"]))
- {
- if($VAR["$field_var"] != '')
- {
- if(!$validate->validate($field_name, $this->field["$value"], $VAR["$field_var"], $this->field["$value"]["validate"]))
- {
- $this->validated = false;
- $this->val_error[] = array('field' => $this->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $this->module, ""),
- 'error' => $validate->error["$field_name"] );
- }
- }
- else
- {
- $this->validated = false;
- $this->val_error[] = array('field' => $this->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $this->module, ""),
- 'error' => $C_translate->translate('validate_any',"", ""));
- }
- }
- else
- {
- $this->validated = false;
- $this->val_error[] = array('field' => $this->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $this->module, ""),
- 'error' => $C_translate->translate('validate_any',"", ""));
- }
- }
- }
-
-
- // validate the tax_id
- require_once(PATH_MODULES.'tax/tax.inc.php');
- $taxObj=new tax;
- $tax_arr = @$VAR['account_admin_tax_id'];
- if(is_array($tax_arr)) {
- foreach($tax_arr as $country_id => $tax_id) {
- if ($country_id == $VAR['account_admin_country_id']) {
- $exempt = @$VAR["account_tax_id_exempt"][$country_id];
- if(!$taxObj->TaxIdsValidate($country_id, $tax_id, $exempt)) {
- $this->validated = false;
- $this->val_error[] = array(
- 'field' => 'account_admin_tax_id',
- 'field_trans' => $taxObj->errField,
- 'error' => $C_translate->translate('validate_general', "", ""));
- }
- if($exempt)
- $account_admin_tax_id=false;
- else
- $account_admin_tax_id=$tax_id;
- }
- }
- }
-
- ####################################################################
- ### Get required static_Vars and validate them... return an array
- ### w/ ALL errors...
- ####################################################################
-
- require_once(PATH_CORE . 'static_var.inc.php');
- $static_var = new CORE_static_var;
-
- if(!isset($this->val_error)) $this->val_error = false;
- $all_error = $static_var->validate_form('account', $this->val_error);
-
- if($all_error != false && gettype($all_error) == 'array')
- $this->validated = false;
- else
- $this->validated = true;
-
-
- ####################################################################
- ### If validation was failed, skip the db insert &
- ### set the errors & origonal fields as Smarty objects,
- ### and change the page to be loaded.
- ####################################################################
-
- if(!$this->validated)
- {
- global $smarty;
-
- # set the errors as a Smarty Object
- $smarty->assign('form_validation', $all_error);
-
- # set the page to be loaded
- if(!defined("FORCE_PAGE"))
- {
- define('FORCE_PAGE', $VAR['_page_current']);
- }
-
- # Stripslashes
- global $C_vars;
- $C_vars->strip_slashes_all();
-
-
- return;
- }
-
- # Get default invoice options
- $db=&DB();
- $invopt=$db->Execute(sqlSelect($db,"setup_invoice","*",""));
- if($invopt && $invopt->RecordCount()) {
- $invoice_delivery=$invopt->fields['invoice_delivery'];
- $invoice_format=$invopt->fields['invoice_show_itemized'];
- }
-
- ####################################################################
- ### Insert the account record
- ####################################################################
- $this->account_id = $db->GenID(AGILE_DB_PREFIX . 'account_id');
- $validation_str = time();
-
- /** get parent id */
- @$parent_id = @$VAR["account_admin_parent_id"];
- if(empty($parent_id)) $parent_id = $this->account_id;
-
- $sql = '
- INSERT INTO ' . AGILE_DB_PREFIX . 'account SET
- id = ' . $db->qstr ( $this->account_id ) . ',
- site_id = ' . $db->qstr ( DEFAULT_SITE ) . ',
- date_orig = ' . $db->qstr ( $validation_str ) . ',
- date_last = ' . $db->qstr ( time()) . ',
- date_expire = ' . $db->qstr ( $date_expire ) . ',
- language_id = ' . $db->qstr ( $VAR["account_admin_language_id"] ) . ',
- country_id = ' . $db->qstr ( $VAR["account_admin_country_id"] ) . ',
- parent_id = ' . $db->qstr ( $parent_id ) . ',
- affiliate_id = ' . $db->qstr ( @$VAR["account_admin_affiliate_id"] ) . ',
- reseller_id = ' . $db->qstr ( @$VAR["account_admin_reseller_id"] ) . ',
- currency_id = ' . $db->qstr ( $VAR["account_admin_currency_id"] ) . ',
- theme_id = ' . $db->qstr ( $VAR["account_admin_theme_id"] ) . ',
- username = ' . $db->qstr ( $VAR["account_admin_username"] ) . ',
- password = ' . $db->qstr ( $VAR["account_admin_password"] ) . ',
- status = ' . $db->qstr ( $status ) . ',
- first_name = ' . $db->qstr ( $VAR["account_admin_first_name"] ) . ',
- middle_name = ' . $db->qstr ( $VAR["account_admin_middle_name"] ) . ',
- last_name = ' . $db->qstr ( $VAR["account_admin_last_name"] ) . ',
- company = ' . $db->qstr ( $VAR["account_admin_company"] ) . ',
- title = ' . $db->qstr ( $VAR["account_admin_title"] ) . ',
- email = ' . $db->qstr ( $VAR["account_admin_email"] ) . ',
- address1 = ' . $db->qstr ( $VAR["account_admin_address1"] ) . ',
- address2 = ' . $db->qstr ( $VAR["account_admin_address2"] ) . ',
- city = ' . $db->qstr ( $VAR["account_admin_city"] ) . ',
- state = ' . $db->qstr ( $VAR["account_admin_state"] ) . ',
- zip = ' . $db->qstr ( $VAR["account_admin_zip"] ) . ',
- misc = ' . $db->qstr ( $VAR["account_admin_misc"] ) . ',
- email_type = ' . $db->qstr ( $VAR["account_admin_email_html"] ) . ',
- invoice_delivery= ' . $db->qstr ( @$invoice_delivery ) . ',
- invoice_show_itemized=' . $db->qstr ( @$invoice_format ) . ',
- invoice_advance_gen = ' . $db->qstr ( MAX_INV_GEN_PERIOD ) . ',
- invoice_grace = ' . $db->qstr ( GRACE_PERIOD ) . ',
- tax_id = ' . $db->qstr ( @$account_tax_id );
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('account_admin.inc.php','add', $db->ErrorMsg());
-
- if(isset($this->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($this->trigger["$type"], 0, $VAR);
- }
- return;
- }
-
- /* password logging class */
- global $C_list;
- if($C_list->is_installed('account_password_history')) {
- include_once(PATH_MODULES.'account_password_history/account_password_history.inc.php');
- $accountHistory = new account_password_history();
- $accountHistory->setNewPassword($this->account_id, $VAR["account_admin_password"]);
- }
-
- ### Add the account to the default group:
- $this->add_account_groups($VAR['groups'], $this->account_id, $VAR['account_admin_date_expire']);
-
- ### Insert the static vars:
- $static_var->add($VAR, 'account', $this->account_id);
-
-
- ### Mail the new user
- if(!empty($VAR['welcome_email'])) {
- require_once(PATH_MODULES . 'email_template/email_template.inc.php');
- $my = new email_template;
- if($status == "1") {
- $my->send('account_add_staff_active', $this->account_id, '', '', $passwd);
- } else {
- $validation_str = strtoupper($validation_str. ':' .$this->account_id);
- $my->send('account_add_staff_inactive', $this->account_id, $this->account_id, '', $validation_str);
- }
- }
-
- ### Do any db_mapping
- if($C_list->is_installed('db_mapping'))
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- if(!empty($passwd))
- $db_map->plaintext_password = $passwd;
- else
- $db_map->plaintext_password = false;
- $db_map->account_add ( $this->account_id );
- }
-
- ### Display the welcome message
- if($status == "1")
- {
- $C_debug->alert($C_translate->translate("staff_add_active","account_admin",""));
-
- } else {
- $C_debug->alert($C_translate->translate("staff_add_inactive","account_admin",""));
- }
-
- #$VAR["id"] = $this->account_id;
- $url = '?_page=' . $VAR['_page'] . '&id=' . $this->account_id;
- if(!empty($VAR['id'])) $url.= '&_escape=1';
- if(!empty($VAR['field']))
- {
- $url .= '&field='.$VAR['field'];
- $url .= '&name='.$VAR['account_admin_first_name'].' '.$VAR['account_admin_last_name'];
- }
-
- define('REDIRECT_PAGE', $url);
-
- ### Affiliate Auto Creation
- if(AUTO_AFFILIATE == 1 && $C_list->is_installed("affiliate"))
- {
- $VAR['affiliate_account_id'] = $this->account_id;
- $VAR['affiliate_template_id'] = DEFAULT_AFFILIATE_TEMPLATE;
- @$VAR['affiliate_parent_affiliate_id'] = $VAR['account_admin_affiliate_id'];
-
- include_once(PATH_MODULES . 'affiliate/affiliate.inc.php');
- $affiliate = new affiliate;
- $affiliate->add($VAR, $affiliate);
- }
-
- return;
- }
-
-
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- if(!$this->checkLimits()) return false; // check account limits
-
- global $C_auth;
-
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
-
- # set the field list for this method:
- $db = &DB();
- $arr = $this->method[$type];
- if(isset($VAR["id"]))
- {
- $id = explode(',',$VAR["id"]);
- for($i=0; $iqstr($id[$i])." ";
- $ii++;
- }
- else
- {
- $id_list .= " OR id = " .$db->qstr($id[$i]). " ";
- $ii++;
- }
- }
- }
- }
-
- if($ii>0)
- {
- # generate the full query
- $q = "SELECT * FROM
- ".AGILE_DB_PREFIX."account
- WHERE
- $id_list
- AND site_id = '" . DEFAULT_SITE . "'";
-
- $result = $db->Execute($q);
-
- # error reporting
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('account_admin.inc.php','view', $db->ErrorMsg() . ' ' . $q);
- return;
- }
-
- # put the results into a smarty accessable array
- $i=0;
- $class_name = TRUE;
- while (!$result->EOF)
- {
- $smart[$i] = $result->fields;
-
- if($class_name)
- {
- $smart[$i]["i"] = $i;
- } else {
- $smart[$i]["i"] = $i;
- }
-
- ### Get any authorized groups:
- $dba = &DB();
- $sql = 'SELECT service_id,group_id FROM ' . AGILE_DB_PREFIX . 'account_group WHERE
- site_id = ' . $dba->qstr(DEFAULT_SITE) . ' AND
- account_id = ' . $dba->qstr($result->fields['id']) . ' AND
- active = ' . $dba->qstr("1") . '
- ORDER BY group_id';
-
- $groups = $dba->Execute($sql);
-
- while (!$groups->EOF)
- {
- if($groups->fields['service_id'] == '') $group[] = $groups->fields['group_id'];
- $groups->MoveNext();
- }
- $smart[$i]["groups"] = $group;
-
- ### Verify the user has access to view this account:
- if(SESS_ACCOUNT != $result->fields['id'])
- {
- $smart[$i]['own_account'] = false;
- $display_this = true;
- for($ix=0; $ixauth_group_by_id($group[$ix]))
- $display_this = false;
- }
- }
- else
- {
- $display_this = true;
- $smart[$i]['own_account'] = true;
- }
-
-
-
-
- ### Get the static vars:
- require_once(PATH_CORE . 'static_var.inc.php');
- $static_var = new CORE_static_var;
- $arr = $static_var->update_form('account', 'update', $result->fields['id']);
- if(gettype($arr) == 'array')
- {
- $smart[$i]["static_var"] = $arr;
- }
-
-
- ### Get the last activity date/IP
- $sql = "SELECT * FROM ".AGILE_DB_PREFIX."login_log
- WHERE account_id = {$result->fields['id']}
- AND site_id = ".DEFAULT_SITE."
- ORDER BY date_orig DESC ";
- $rslast = $db->SelectLimit($sql, 1);
- if($rslast != false && $rslast->RecordCount() == 1) {
- $smart[$i]["last_activity"] = $rslast->fields['date_orig'];
- $smart[$i]["last_ip"] = $rslast->fields['ip'];
- } else {
- $smart[$i]["last_activity"] = $result->fields['date_orig'];
- $smart[$i]["last_ip"] = '';
- }
-
-
- ### Get invoice details for this account:
- $sql = "SELECT id,date_orig,total_amt,billed_amt,process_status FROM ".AGILE_DB_PREFIX."invoice
- WHERE account_id = {$result->fields['id']}
- AND site_id = ".DEFAULT_SITE."
- ORDER BY id DESC ";
- $inv = $db->SelectLimit($sql, 10);
- if($inv != false && $inv->RecordCount() > 0) {
- while(!$inv->EOF) {
- if($inv->fields['total_amt'] > $inv->fields['billed_amt'] && $inv->fields['suspend_billing'] != 1) {
- $inv->fields['due'] = $inv->fields['total_amt'] - $inv->fields['billed_amt'];
- }
- $smart[$i]["invoice"][] = $inv->fields;
- $inv->MoveNext();
- }
- }
-
-
- ### Get service details for this account:
- $sql = "SELECT id,sku,active,type,domain_name,domain_tld FROM ".AGILE_DB_PREFIX."service
- WHERE account_id = {$result->fields['id']}
- AND site_id = ".DEFAULT_SITE."
- ORDER BY id DESC ";
- $svc = $db->SelectLimit($sql, 10);
- if($svc != false && $svc->RecordCount() > 0) {
- while(!$svc->EOF) {
- $smart[$i]["service"][] = $svc->fields;
- $svc->MoveNext();
- }
- }
-
-
- # define the results
- if(!$display_this)
- {
- unset($smart["$i"]);
- echo "You have selected an account for which you are not authorized,
- your permission settings are to low! ";
- }
- else
- {
- $i++;
- }
- unset($group);
- $result->MoveNext();
- }
-
- # get the result count:
- $results = $i;
-
- ### No results:
- if($i == 0)
- {
- global $C_debug;
- $C_debug->error("CORE:account_admin.inc.php", "view()", "
- The selected record does not exist any longer, or your account is not authorized to view it");
- return;
- }
-
-
- global $smarty;
- $smarty->assign($this->table, $smart);
- $smarty->assign('results', $search->results);
- }
- }
-
-
-
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- global $C_list, $C_debug;
-
- if(!$this->checkLimits()) return false; // check account limits
-
- // validate the tax_id
- global $VAR;
- require_once(PATH_MODULES.'tax/tax.inc.php');
- $taxObj=new tax;
- $tax_arr = @$VAR['account_admin_tax_id'];
- if(is_array($tax_arr)) {
- foreach($tax_arr as $country_id => $tax_id) {
- if ($country_id == $VAR['account_admin_country_id']) {
- $exempt = @$VAR["account_tax_id_exempt"][$country_id];
- if(!$txRs=$taxObj->TaxIdsValidate($country_id, $tax_id, $exempt)) {
- $this->validated = false;
- global $C_translate;
- $this->val_error[] = array(
- 'field' => 'account_admin_tax_id',
- 'field_trans' => $taxObj->errField,
- 'error' => $C_translate->translate('validate_general', "", ""));
- }
- if($exempt)
- $VAR['account_admin_tax_id']=false;
- else
- $VAR['account_admin_tax_id']=$tax_id;
- }
- }
- }
-
- ####################################################################
- ### Get required static_Vars and validate them... return an array
- ### w/ ALL errors...
- ####################################################################
-
- require_once(PATH_CORE . 'static_var.inc.php');
- $static_var = new CORE_static_var;
- if(!isset($this->val_error)) $this->val_error = false;
- $all_error = $static_var->validate_form('account', $this->val_error);
-
- if($all_error != false && gettype($all_error) == 'array')
- $this->validated = false;
- else
- $this->validated = true;
-
- ####################################################################
- # If validation was failed, skip the db insert &
- # set the errors & origonal fields as Smarty objects,
- # and change the page to be loaded.
- ####################################################################
-
- if(!$this->validated)
- {
- global $smarty;
-
- # set the errors as a Smarty Object
- $smarty->assign('form_validation', $all_error);
-
- # set the page to be loaded
- if(!defined("FORCE_PAGE"))
- {
- define('FORCE_PAGE', $VAR['_page_current']);
- }
- return;
- }
-
- ### Get the old username ( for db mapping )
- $db = &DB();
- $sql = 'SELECT username FROM ' . AGILE_DB_PREFIX . 'account WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($VAR['account_admin_id']);
- $result = $db->Execute($sql);
- if($result->RecordCount() > 0)
- {
- $old_username = $result->fields['username'];
- }
-
- ### Update the password:
- $update_password=false;
- if(!empty($VAR['_password'])) {
- $VAR['account_admin_password'] = $VAR['_password'];
-
- /* check if new password is ok */
- if($C_list->is_installed('account_password_history')) {
- include_once(PATH_MODULES.'account_password_history/account_password_history.inc.php');
- $accountHistory = new account_password_history();
- if(!$accountHistory->getIsPasswordOk($VAR['account_admin_id'], $VAR['account_admin_password'], false)) {
- $C_debug->alert("The password you have selected has been used recently and cannot be used again at this time for security purposes.");
- unset($VAR['account_admin_password']);
- } else {
- $update_password=true;
- }
- }
- }
-
- ### Update the record
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $ok = $db->update($VAR, $this, $type);
-
- if($ok)
- {
- /* password logging class */
- if($update_password && is_object($accountHistory)) $accountHistory->setNewPassword($VAR['account_admin_id'], $VAR["account_admin_password"], false);
-
- ### Update the static vars:
- $static_var->update($VAR, 'account', $VAR['account_admin_id']);
-
- ### Do any db_mapping
- if($C_list->is_installed('db_mapping'))
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
-
- if(!empty($VAR['account_admin_password']))
- $db_map->plaintext_password = $VAR['account_admin_password'];
- else
- $db_map->plaintext_password = false;
-
- $db_map->account_edit ( $VAR['account_admin_id'], $old_username );
- }
-
- // remove login lock
- if($VAR['account_admin_status']) {
- $db=&DB();
- $delrs = $db->Execute($sql=sqlDelete($db,"login_lock","account_id={$VAR['account_admin_id']}"));
- $delrs = $db->Execute($sql=sqlDelete($db,"login_log","account_id={$VAR['account_admin_id']} AND status=0"));
- }
- return true;
- }
- }
-
-
-
- ##############################
- ## MERGE ##
- ##############################
- function merge($VAR)
- {
- $db = &DB();
- global $C_auth, $C_list, $C_translate, $C_debug;
-
- if(empty($VAR['id']) || empty($VAR['merge_acct_id'])) {
- $C_debug->alert($C_translate->translate('merge_err','account_admin',''));
- return false;
- }
-
- $acct_id = $VAR['id'];
- $merge_acct_id = $VAR['merge_acct_id'];
-
- # Get merged account_group
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."account_group WHERE (
- service_id = '' OR
- service_id = 0 OR
- service_id IS NULL
- ) AND account_id = $acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) {
- $C_debug->error('account_admin.inc.php','merge :: account_group', $db->ErrorMsg());
- } else {
- while(!$rs->EOF) {
- $Cauth = new CORE_auth(true);
- if($Cauth->auth_group_by_account_id($merge_acct_id, $rs->fields['group_id'])) {
- # duplicate group, delete
- $q = "DELETE FROM ".AGILE_DB_PREFIX."account_group WHERE id = {$rs->fields['id']} AND site_id = ".DEFAULT_SITE;
- $db->Execute($q);
- }
- $rs->MoveNext();
- }
- }
-
- # account_group
- $q = "UPDATE ".AGILE_DB_PREFIX."account_group SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: account_group', $db->ErrorMsg());
-
- # account_billing
- $q = "UPDATE ".AGILE_DB_PREFIX."account_billing SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: account_billing', $db->ErrorMsg());
-
- # cart
- $q = "UPDATE ".AGILE_DB_PREFIX."cart SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: cart', $db->ErrorMsg());
-
- # charge
- $q = "UPDATE ".AGILE_DB_PREFIX."charge SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: charge', $db->ErrorMsg());
-
- # discount
- $q = "UPDATE ".AGILE_DB_PREFIX."discount SET avail_account_id = $acct_id WHERE avail_account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: charge', $db->ErrorMsg());
-
- # invoice
- $q = "UPDATE ".AGILE_DB_PREFIX."invoice SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: invoice', $db->ErrorMsg());
-
- # log_error
- $q = "UPDATE ".AGILE_DB_PREFIX."log_error SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: log_error', $db->ErrorMsg());
-
- # login_lock
- $q = "DELETE FROM ".AGILE_DB_PREFIX."login_lock WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: login_lock', $db->ErrorMsg());
-
- # login_log
- $q = "UPDATE ".AGILE_DB_PREFIX."login_log SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: login_log', $db->ErrorMsg());
-
- # search
- $q = "UPDATE ".AGILE_DB_PREFIX."search SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: search', $db->ErrorMsg());
-
- # service
- $q = "UPDATE ".AGILE_DB_PREFIX."service SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: service', $db->ErrorMsg());
-
- # session
- $q = "DELETE FROM ".AGILE_DB_PREFIX."session WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: session', $db->ErrorMsg());
-
- # staff
- $q = "UPDATE ".AGILE_DB_PREFIX."staff SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: staff', $db->ErrorMsg());
-
- # affiliate
- if($C_list->is_installed('affiliate'))
- {
- $q = "UPDATE ".AGILE_DB_PREFIX."affiliate SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: affiliate', $db->ErrorMsg());
- }
-
- # ticket
- if($C_list->is_installed('ticket'))
- {
- $q = "UPDATE ".AGILE_DB_PREFIX."ticket SET account_id = $acct_id WHERE account_id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: ticket', $db->ErrorMsg());
- }
-
- # DB Mapping
- if($C_list->is_installed('db_mapping'))
- {
- $dbsql = "SELECT username FROM ".AGILE_DB_PREFIX."account WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- id = ".$db->qstr($merge_acct_id);
- $resultdb = $db->Execute($dbsql);
- $old_username = $resultdb->fields['username'];
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- $db_map->account_delete ( $merge_acct_id, $old_username );
- }
-
- # Delete account
- $q = "DELETE FROM ".AGILE_DB_PREFIX."account WHERE id = $merge_acct_id AND site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($q);
- if ($rs === false) $C_debug->error('account_admin.inc.php','merge :: account', $db->ErrorMsg());
-
- $C_debug->alert($C_translate->translate('merge_ok','account_admin',''));
- return;
-
- }
-
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = &DB();
- global $C_auth, $C_list;
-
- # set the id
- $id = $this->table . '_id';
-
- # generate the list of ID's
- $id_list = '';
- $account_id_list = '';
- $discount_id_list = '';
- $ii=0;
-
- if(isset($VAR["delete_id"]))
- {
- $id = explode(',',$VAR["delete_id"]);
- }
- elseif (isset($VAR["id"]))
- {
- $id = explode(',',$VAR["id"]);
- }
-
- for($i=0; $iExecute($sql);
- while (!$groups->EOF)
- {
- $group[] = $groups->fields['group_id'];
- $groups->MoveNext();
- }
-
- ### Verify the user has access to view this account:
- $delete_this = true;
- if(!empty($group) && is_array($group)) {
- for($ix=0; $ixauth_group_by_id($group[$ix]))
- {
- $delete_this = false;
- $ix = count($group);
- }
- }
- }
- unset($group);
-
- ### Verify this is not the admin account or the current user's account:
- if(SESS_ACCOUNT == $id[$i] || $id[$i] == '1')
- $delete_this = false;
-
- ### Generate the SQL
- if($delete_this)
- {
- if($i == 0) {
- $id_list .= " id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- $account_id_list .= " account_id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- $discount_id_list .= " account_id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- $ii++;
- } else {
- $id_list .= " OR id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- $account_id_list .= " OR account_id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- $discount_id_list .= " OR account_id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- $ii++;
- }
-
- ####################################################################
- ### Do any db_mapping
- ####################################################################
-
- $dbsql = "SELECT username FROM ".AGILE_DB_PREFIX."account WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- id = ".$db->qstr($id[$i]);
- $resultdb = $db->Execute($dbsql);
- $old_username = $resultdb->fields['username'];
-
- if($C_list->is_installed('db_mapping'))
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- $db_map->account_delete ( $id[$i], $old_username );
- }
- }
- }
- }
-
- $db = &DB();
- if($ii>0)
- {
- # generate the full query (account)
- $q = "DELETE FROM ".AGILE_DB_PREFIX."account
- WHERE $id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $result = $db->Execute($q);
-
- # generate the full query (sessions)
- $q = "DELETE FROM ".AGILE_DB_PREFIX."session
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
-
- # generate the full query (account_billing)
- $q = "DELETE FROM ".AGILE_DB_PREFIX."account_billing
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
-
- # generate the full query (account_group)
- $q = "DELETE FROM ".AGILE_DB_PREFIX."account_group
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
-
- # generate the full query (cart)
- $q = "DELETE FROM ".AGILE_DB_PREFIX."cart
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
-
- # generate the full query (search)
- $q = "DELETE FROM ".AGILE_DB_PREFIX."search
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
-
- # generate the full query (staff)
- $q = "DELETE FROM ".AGILE_DB_PREFIX."staff
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
-
- # generate the full query (ticket)
- if($C_list->is_installed('ticket'))
- {
- $q = "SELECT id FROM ".AGILE_DB_PREFIX."ticket
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $ticket = $db->Execute($q);
- if($ticket != false && $ticket->RecordCount() > 0) {
- while( !$ticket->EOF ) {
- include_once(PATH_MODULES.'ticket/ticket.inc.php');
- $tk = new ticket;
- $arr['id'] = $ticket->fields['id'];
- $tk->delete($arr, $tk);
- $ticket->MoveNext();
- }
- }
- }
-
- # generate the full query (affiliate)
- if($C_list->is_installed('affiliate'))
- {
- $q = "DELETE FROM ".AGILE_DB_PREFIX."affiliate
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
- }
-
- # generate the full query (discount)
- $q = "DELETE FROM ".AGILE_DB_PREFIX."discount
- WHERE $discount_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
-
- # generate the full query (invoice)
- $q = "SELECT id FROM ".AGILE_DB_PREFIX."invoice
- WHERE $account_id_list AND site_id = ".$db->qstr(DEFAULT_SITE);
- $invoice = $db->Execute($q);
- if($invoice != false && $invoice->RecordCount() > 0 ) {
- while( !$invoice->EOF ) {
- include_once(PATH_MODULES.'invoice/invoice.inc.php');
- $inv = new invoice;
- $arr['id'] = $invoice->fields['id'];
- $inv->delete($arr, $inv);
- $invoice->MoveNext();
- }
- }
-
- # error reporting
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('account_admin.inc.php','delete', $db->ErrorMsg());
-
- }
- else
- {
- # Alert delete message
- global $C_debug, $C_translate;
- $C_translate->value["CORE"]["module_name"] = $C_translate->translate('name','account_admin',"");
- $message = $C_translate->translate('alert_delete_ids',"CORE","");
- $C_debug->alert($message);
- }
- }
- }
-
-
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
-
-
-
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
-
- $db = &DB();
-
- include_once(PATH_CORE . 'validate.inc.php');
- $validate = new CORE_validate;
-
- # set the search criteria array
- $arr = $VAR;
-
- # loop through the submitted field_names to get the WHERE statement
- $where_list = '';
- $i=0;
- while (list ($key, $value) = each ($arr))
- {
- if($i == 0)
- {
- if($value != '')
- {
- $pat = "^" . $this->module . "_";
- if(eregi($pat, $key))
- {
- $field = eregi_replace($pat,"",$key);
- if(eregi('%',$value))
- {
- # do any data conversion for this field (date, encrypt, etc...)
- if(isset($this->field["$field"]["convert"]))
- {
- $value = $validate->convert($field, $value, $this->field["$field"]["convert"]);
- }
-
- $where_list .= " WHERE ".AGILE_DB_PREFIX."account.".$field . " LIKE " . $db->qstr($value, get_magic_quotes_gpc());
- $i++;
- }
- else
- {
- # check if array
- if(is_array($value))
- {
- for($i_arr=0; $i_arr < count($value); $i_arr++)
- {
- if($value["$i_arr"] != '')
- {
- # determine any field options (=, >, <, etc...)
- $f_opt = '=';
- $pat_field = $this->module.'_'.$field;
- $VAR['field_option']["$pat_field"]["$i_arr"];
- if(isset($VAR['field_option']["$pat_field"]["$i_arr"]))
- {
- $f_opt = $VAR['field_option']["$pat_field"]["$i_arr"];
- # error checking, safety precaution
- if($f_opt != '=' && $f_opt != '>' && $f_opt != '<' && $f_opt != '>=' && $f_opt != '<=' && $f_opt != '!=')
- $f_opt = '=';
- }
-
- # do any data conversion for this field (date, encrypt, etc...)
- if(isset($this->field["$field"]["convert"]))
- {
- $value["$i_arr"] = $validate->convert($field, $value["$i_arr"], $this->field["$field"]["convert"]);
- }
-
-
- if($i_arr == 0)
- {
- $where_list .= " WHERE ".AGILE_DB_PREFIX."account.".$field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
- $i++;
- }
- else
- {
- $where_list .= " AND ".AGILE_DB_PREFIX."account.".$field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
- $i++;
- }
- }
- }
- }
- else
- {
- $where_list .= " WHERE ".AGILE_DB_PREFIX."account.".$field . " = " . $db->qstr($value, get_magic_quotes_gpc());
- $i++;
- }
- }
- }
- }
- }
- else
- {
- if($value != '')
- {
- $pat = "^" . $this->module . "_";
- if(eregi($pat, $key))
- {
- $field = eregi_replace($pat,"",$key);
- if(eregi('%',$value))
- {
- # do any data conversion for this field (date, encrypt, etc...)
- if(isset($this->field["$field"]["convert"]))
- {
- $value = $validate->convert($field, $value, $this->field["$field"]["convert"]);
- }
-
- $where_list .= " AND ".AGILE_DB_PREFIX."account.".$field . " LIKE " . $db->qstr($value, get_magic_quotes_gpc());
- $i++;
- }
- else
- {
- # check if array
- if(is_array($value))
- {
- for($i_arr=0; $i_arr < count($value); $i_arr++)
- {
- if($value["$i_arr"] != '')
- {
- # determine any field options (=, >, <, etc...)
- $f_opt = '=';
- $pat_field = $this->module.'_'.$field;
- if(isset($VAR['field_option']["$pat_field"]["$i_arr"]))
- {
- $f_opt = $VAR['field_option']["$pat_field"]["$i_arr"];
-
- # error checking, safety precaution
- if($f_opt != '=' && $f_opt != '>' && $f_opt != '<' && $f_opt != '>=' && $f_opt != '<=' && $f_opt != '!=')
- $f_opt = '=';
- }
-
- # do any data conversion for this field (date, encrypt, etc...)
- if(isset($this->field["$field"]["convert"]))
- {
- $value["$i_arr"] = $validate->convert($field, $value["$i_arr"], $this->field["$field"]["convert"]);
- }
-
- $where_list .= " AND ".AGILE_DB_PREFIX."account.". $field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
- $i++;
- }
- }
- }
- else
- {
- $where_list .= " AND ".AGILE_DB_PREFIX."account.". $field . " = ". $db->qstr($value, get_magic_quotes_gpc());
- $i++;
- }
- }
- }
- }
- }
- }
-
- #### finalize the WHERE statement
- if($where_list == '')
- {
- $where_list .= ' WHERE ';
- }
- else
- {
- $where_list .= ' AND ';
- }
-
-
- # get limit type
- if(isset($VAR['limit']))
- {
- $limit = $VAR['limit'];
- }
- else
- {
- $limit = $this->limit;
- }
-
- # get order by
- if(isset($VAR['order_by']))
- {
- $order_by = $VAR['order_by'];
- }
- else
- {
- $order_by = $this->order_by;
- }
-
- $pre = AGILE_DB_PREFIX;
-
- $q = "SELECT DISTINCT ".AGILE_DB_PREFIX."account.id,".AGILE_DB_PREFIX."account.last_name,".AGILE_DB_PREFIX."account.first_name,".AGILE_DB_PREFIX."account.username FROM ".AGILE_DB_PREFIX."account ";
- $q_save = "SELECT DISTINCT %%fieldList%% FROM ".AGILE_DB_PREFIX."account ";
-
- # Code for group searches:
- if(!empty($VAR['account_group']))
- $q .= " LEFT JOIN ".AGILE_DB_PREFIX."account_group ON ".AGILE_DB_PREFIX."account_group.account_id = ".AGILE_DB_PREFIX."account.id";
-
-
- ######## GET ANY STATIC VARS TO SEARCH ##########
- $join_list = '';
- if(!empty($VAR["static_relation"]) && count( $VAR["static_relation"] > 0 )) {
- while(list($idx, $value) = each ($VAR["static_relation"])) {
- if($value != "") {
-
- $join_list .= " INNER JOIN {$pre}static_var_record AS s{$idx} ON
- (
- s{$idx}.record_id = {$pre}{$this->table}.id
- AND
- s{$idx}.static_var_relation_id = '{$idx}'
- AND
- s{$idx}.site_id = ".$db->qstr(DEFAULT_SITE)."
- AND";
- if(ereg("%", $value))
- $join_list .= " s{$idx}.value LIKE ".$db->qstr($VAR["static_relation"]["$idx"]);
- else
- $join_list .= " s{$idx}.value = ".$db->qstr($VAR["static_relation"]["$idx"]);
- $join_list .= " ) ";
- }
- }
- }
- ######## END STATIC VAR SEARCH ##################
-
-
- # standard where list
- $q .= $join_list . $where_list ." ".AGILE_DB_PREFIX."account.site_id = " . $db->qstr(DEFAULT_SITE);
-
- # Code for member group:
- if(!empty($VAR['account_group'])) {
- $q .= " AND ".AGILE_DB_PREFIX."account_group.group_id = " . $db->qstr($VAR['account_group'])."
- AND ".AGILE_DB_PREFIX."account_group.site_id = " . $db->qstr(DEFAULT_SITE);
- }
- if(!empty($VAR['account_group']))
- {
- $q_save .= " LEFT JOIN ".AGILE_DB_PREFIX."account_group ON ".AGILE_DB_PREFIX."account_group.account_id = ".AGILE_DB_PREFIX."account.id ";
-
- if(!empty($join_list))
- $q_save .= $join_list;
-
- $q_save .= $where_list ." %%whereList%% ";
- $q_save .= AGILE_DB_PREFIX."account_group.group_id = " . $db->qstr($VAR['account_group'])." AND ";
- }
- else
- {
- if(!empty($join_list))
- $q_save .= $join_list;
-
- $q_save .= $where_list ." %%whereList%% ";
- }
-
- ################## DEBUG ##################
- #echo "" . $q;
- #echo " " . $q_save;
- #exit;
-
- # run the database query
- $result = $db->Execute($q);
-
- # error reporting
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('database.inc.php','search', $db->ErrorMsg());
- return false;
- }
-
- # get the result count:
- $results = $result->RecordCount();
-
- # get the first record id:
- if($results == 1) $record_id = $result->fields['id'];
-
- # define the DB vars as a Smarty accessible block
- global $smarty;
-
- # Create the definition for fast-forwarding to a single record:
- if ($results == 1 && !isset($this->fast_forward))
- {
- $smarty->assign('record_id', $record_id);
- }
-
- # create the search record:
- if($results > 0)
- {
- # create the search record
- include_once(PATH_CORE . 'search.inc.php');
- $search = new CORE_search;
- $arr['module'] = $this->module;
- $arr['sql'] = $q_save;
- $arr['limit'] = $limit;
- $arr['order_by']= $order_by;
- $arr['results'] = $results;
- $search->add($arr);
-
- # define the search id and other parameters for Smarty
- $smarty->assign('search_id', $search->id);
-
- # page:
- $smarty->assign('page', '1');
-
- # limit:
- $smarty->assign('limit', $limit);
-
- # order_by:
- $smarty->assign('order_by', $order_by);
- }
-
- # define the result count
- $smarty->assign('results', $results);
- }
-
-
-
-
-
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
-
- # set the field list for this method:
- $arr = $this->method[$type];
-
- $field_list = '';
- $i=0;
- while (list ($key, $value) = each ($arr))
- {
- if($i == 0)
- {
- $field_var = $this->table . '_' . $value;
- $field_list .= AGILE_DB_PREFIX . "account" . "." . $value;
-
- // determine if this record is linked to another table/field
- if($this->field[$value]["asso_table"] != "")
- {
- $this->linked[] = array('field' => $value, 'link_table' => $this->field[$value]["asso_table"], 'link_field' => $this->field[$value]["asso_field"]);
- }
- }
- else
- {
- $field_var = $this->table . '_' . $value;
- $field_list .= "," . AGILE_DB_PREFIX . "account" . "." . $value;
-
- // determine if this record is linked to another table/field
- if($this->field[$value]["asso_table"] != "")
- {
- $this->linked[] = array('field' => $value, 'link_table' => $this->field[$value]["asso_table"], 'link_field' => $this->field[$value]["asso_field"]);
- }
- }
- $i++;
- }
-
-
- # get the search details:
- if(isset($VAR['search_id'])) {
- include_once(PATH_CORE . 'search.inc.php');
- $search = new CORE_search;
- $search->get($VAR['search_id']);
- } else {
- # invalid search!
- echo ' The search terms submitted were invalid!'; # translate... # alert
-
- if(isset($this->trigger["$type"])) {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($this->trigger["$type"], 0, $VAR);
- }
- }
-
- # get the sort order details:
- if(isset($VAR['order_by']) && $VAR['order_by'] != "") {
- $order_by = ' ORDER BY ' . AGILE_DB_PREFIX . 'account.'.$VAR['order_by'];
- $smarty_order = $VAR['order_by'];
- } else {
- $order_by = ' ORDER BY ' . AGILE_DB_PREFIX . 'account.'.$this->order_by;
- $smarty_order = $search->order_by;
- }
-
-
- # determine the sort order
- if(isset($VAR['desc'])) {
- $order_by .= ' DESC';
- $smarty_sort = 'desc=';
- } else if(isset($VAR['asc'])) {
- $order_by .= ' ASC';
- $smarty_sort = 'asc=';
- } else {
- if (!eregi('date',$smarty_order)) {
- $order_by .= ' ASC';
- $smarty_sort = 'asc=';
- } else {
- $order_by .= ' DESC';
- $smarty_sort = 'desc=';
- }
- }
-
- # generate the full query
-
- $db = &DB();
- $q = eregi_replace("%%fieldList%%", $field_list, $search->sql);
- $q = eregi_replace("%%tableList%%", AGILE_DB_PREFIX.$construct->table, $q);
- $q = eregi_replace("%%whereList%%", "", $q);
- $q .= " ".AGILE_DB_PREFIX . "account."."site_id = " . $db->qstr(DEFAULT_SITE);
- $q .= $order_by;
-
- //////////////////
- #echo " $q ";
- $current_page=1;
- $offset=-1;
- if (!empty($VAR['page'])) $current_page = $VAR['page'];
- if (empty($search->limit)) $search->limit=25;
- if($current_page>1) $offset = (($current_page * $search->limit) - $search->limit);
- $result = $db->SelectLimit($q, $search->limit, $offset);
-
-
- # error reporting
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('database.inc.php','search', $db->ErrorMsg());
-
- if(isset($this->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($this->trigger["$type"], 0, $VAR);
- }
- return;
- }
-
-
- # put the results into a smarty accessable array
- $i=0;
- $class_name = TRUE;
- while (!$result->EOF) {
- $smart[$i] = $result->fields;
-
- if($class_name)
- {
- $smart[$i]['_C'] = 'row1';
- $class_name = FALSE;
- } else {
- $smart[$i]['_C'] = 'row2';
- $class_name = TRUE;
- }
- $result->MoveNext();
- $i++;
- }
-
-
- # get any linked fields
- if($i > 0)
- {
- $db_join = new CORE_database;
- $this->result = $db_join->join_fields($smart, $this->linked);
- }
- else
- {
- $this->result = $smart;
- }
-
- # get the result count:
- $results = $result->RecordCount();
-
- # define the DB vars as a Smarty accessible block
- global $smarty;
-
- # define the results
- $smarty->assign($this->table, $this->result);
- $smarty->assign('page', $VAR['page']);
- $smarty->assign('order', $smarty_order);
- $smarty->assign('sort', $smarty_sort);
- $smarty->assign('limit', $search->limit);
- $smarty->assign('search_id',$search->id);
- $smarty->assign('results', $search->results);
-
- # get the total pages for this search:
- if(empty($search->limit))
- $this->pages = 1;
- else
- $this->pages = intval($search->results / $search->limit);
- if ($search->results % $search->limit) $this->pages++;
-
- # total pages
- $smarty->assign('pages', $this->pages);
-
- # current page
- $smarty->assign('page', $current_page);
- $page_arr = '';
- for($i=0; $i <= $this->pages; $i++)
- {
- if ($this->page != $i) $page_arr[] = $i;
- }
-
- # page array for menu
- $smarty->assign('page_arr', $page_arr);
- }
-
-
-
- ##############################
- ## SEARCH EXPORT ##
- ##############################
- function search_export($VAR)
- {
- if(!$this->checkLimits()) return false; // check account limits
-
- # require the export class
- require_once (PATH_CORE . "export.inc.php");
-
- # Call the correct export function for inline browser display, download, email, or web save.
- if($VAR["format"] == "excel")
- {
- $type = "export_excel";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $export = new CORE_export;
- $export->search_excel($VAR, $this, $type);
- }
-
- else if ($VAR["format"] == "pdf")
- {
- $type = "export_pdf";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $export = new CORE_export;
- $export->search_pdf($VAR, $this, $type);
- }
-
- else if ($VAR["format"] == "xml")
- {
- $type = "export_xml";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $export = new CORE_export;
- $export->search_xml($VAR, $this, $type);
- }
-
- else if ($VAR["format"] == "csv")
- {
- $type = "export_csv";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $export = new CORE_export;
- $export->search_csv($VAR, $this, $type);
- }
-
- else if ($VAR["format"] == "tab")
- {
- $type = "export_tab";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $export = new CORE_export;
- $export->search_tab($VAR, $this, $type);
- }
- }
-
-
-
-
- ##############################
- ## ADD GROUPS ##
- ##############################
-
- function add_account_groups($groups, $account, $expire)
- {
- global $C_auth;
- $ii = 0;
-
- #loop through the array to add each account_group record
- for($i=0; $iauth_group_by_id($groups[$i]))
- {
-
- # add the account to the selected groups...
- $dba = &DB();
-
- # determine the record id:
- $this->new_id = $dba->GenID(AGILE_DB_PREFIX . "" . 'account_group_id');
-
- # generate the full query
- $q = "INSERT INTO ".AGILE_DB_PREFIX."account_group
- SET
- id = ". $dba->qstr($this->new_id).",
- date_orig = ". $dba->qstr(time()).",
- date_expire = ". $dba->qstr($expire).",
- group_id = ". $dba->qstr($groups[$i]).",
- account_id = ". $dba->qstr($account).",
- active = ". $dba->qstr('1').",
- site_id = ". $dba->qstr(DEFAULT_SITE);
-
- # execute the query
- $result = $dba->Execute($q);
- $ii++;
-
- # error reporting:
- if ($result === false) {
- global $C_debug;
- $C_debug->error('account_admin.inc.php','add_account_groups', $dba->ErrorMsg());
- }
- }
- }
-
- ### Add default group
- if($ii == 0)
- {
- # add the account to the selected groups...
- $dba = &DB();
-
- # determine the record id:
- $this->new_id = $dba->GenID(AGILE_DB_PREFIX . "" . 'account_group_id');
-
- # generate the full query
- $q = "INSERT INTO ".AGILE_DB_PREFIX."account_group
- SET
- id = ". $dba->qstr($this->new_id).",
- date_orig = ". $dba->qstr(time()).",
- date_expire = ". $dba->qstr($expire).",
- group_id = ". $dba->qstr(DEFAULT_GROUP).",
- account_id = ". $dba->qstr($account).",
- active = ". $dba->qstr('1').",
- site_id = ". $dba->qstr(DEFAULT_SITE);
-
- # execute the query
- $result = $dba->Execute($q);
- if ($result === false) {
- global $C_debug;
- $C_debug->error('account_admin.inc.php','add_account_groups', $dba->ErrorMsg());
- }
- }
- }
-
-
-
-
- ##############################
- ## UDPATE GROUPS ##
- ##############################
-
- function update_account_groups($VAR)
- {
- global $C_auth;
- $ii = 0;
- @$groups = $VAR['groups'];
- @$account = $VAR['account_admin_id'];
-
- # admin accounts groups cannot be altered
- # user cannot modify their own groups
- if($account == "1" || SESS_ACCOUNT == $account)
- return false;
-
- ### Drop the current groups for this account:
- # generate the full query
- $dba = &DB();
- $q = "DELETE FROM ".AGILE_DB_PREFIX."account_group
- WHERE
- service_id IS NULL AND
- account_id = ". $dba->qstr($account)." AND
- site_id = ". $dba->qstr(DEFAULT_SITE);
- # execute the query
- $result = $dba->Execute($q);
-
- #loop through the array to add each account_group record
- for($i=0; $iauth_group_by_id($groups[$i]))
- {
- # add the account to the selected groups...
- $dba = &DB();
-
- # determine the record id:
- $this->new_id = $dba->GenID(AGILE_DB_PREFIX . "" . 'account_group_id');
-
- # determine the expiration
- if(!empty($VAR['account_admin_date_expire']))
- {
- include_once(PATH_CORE.'validate.inc.php');
- $validate = new CORE_validate;
- $expire = $validate->DateToEpoch(DEFAULT_DATE_FORMAT,$VAR['account_admin_date_expire']);
- } else {
- $expire = 0;
- }
-
- # generate the full query
- $q = "INSERT INTO ".AGILE_DB_PREFIX."account_group
- SET
- id = ". $dba->qstr($this->new_id).",
- date_orig = ". $dba->qstr(time()).",
- date_expire = ". $dba->qstr($expire).",
- group_id = ". $dba->qstr($groups[$i]).",
- account_id = ". $dba->qstr($account).",
- active = ". $dba->qstr('1').",
- site_id = ". $dba->qstr(DEFAULT_SITE);
-
- # execute the query
- $result = $dba->Execute($q);
- $ii++;
-
- # error reporting:
- if ($result === false) {
- global $C_debug;
- $C_debug->error('account_admin.inc.php','update_account_groups', $dba->ErrorMsg());
- }
- }
- }
-
- ### Add default group
- if($ii == 0)
- {
- # add the account to the selected groups...
- $dba = &DB();
-
- # determine the record id:
- $this->new_id = $dba->GenID(AGILE_DB_PREFIX . "" . 'account_group_id');
-
- # generate the full query
- $q = "INSERT INTO ".AGILE_DB_PREFIX."account_group
- SET
- id = ". $dba->qstr($this->new_id).",
- date_orig = ". $dba->qstr(time()).",
- date_expire = ". $dba->qstr(@$expire).",
- group_id = ". $dba->qstr(DEFAULT_GROUP).",
- account_id = ". $dba->qstr($account).",
- active = ". $dba->qstr('1').",
- site_id = ". $dba->qstr(DEFAULT_SITE);
- $result = $dba->Execute($q);
- if ($result === false) {
- global $C_debug;
- $C_debug->error('account_admin.inc.php','update_account_groups', $dba->ErrorMsg());
- }
- }
-
- ### Remove the user's session_auth_cache so it is regenerated on user's next pageview
- $db = &DB();
- $q = "SELECT id FROM ".AGILE_DB_PREFIX."session WHERE
- account_id = ".$db->qstr($account)." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $rss = $db->Execute($q);
- while(!$rss->EOF)
- {
- $q = "DELETE FROM ".AGILE_DB_PREFIX."session_auth_cache WHERE
- session_id = ".$db->qstr($rss->fields['id'])." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $db->Execute($q);
- $rss->MoveNext();
- }
-
- ### Do any db_mapping
- global $C_list;
- if($C_list->is_installed('db_mapping'))
- {
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- $db_map->account_group_sync ( $account );
- }
- }
-}
-?>
\ No newline at end of file
diff --git a/modules/account_admin/account_admin_construct.xml b/modules/account_admin/account_admin_construct.xml
deleted file mode 100644
index 5f24d706..00000000
--- a/modules/account_admin/account_admin_construct.xml
+++ /dev/null
@@ -1,180 +0,0 @@
-
-
-
- account_admin
-
-
-
- account
-
- 0
-
- last_name
-
- 30
-
-
-
- I8
- 1
-
-
- I4
-
-
- I8
- date-time
-
-
- I8
- date-now
-
-
- I8
- date
-
-
- I4
-
-
- C(32)
-
-
- I4
-
-
- I4
-
-
- I4
-
-
- I4
-
-
- I4
-
-
- C(32)
-
-
- C(128)
- 4
- 128
- any
- 1
-
-
- C(128)
- 4
- 128
- password
- md5
-
-
- L
-
-
- C2(128)
-
-
- I4
- 0
-
-
- C(128)
- 1
- 128
- any
-
-
- C(128)
-
-
- C(128)
- 1
- 128
- any
-
-
- C(128)
-
-
- C(255)
- 4
- 128
- email
- 1
-
-
- C(255)
-
-
- C(128)
- 3
- 128
- any
-
-
- C(128)
- 128
-
-
- C(32)
- 2
- 32
- any
-
-
- C(32)
- 2
- 32
- any
-
-
- C(16)
- 4
- 16
- any
-
-
- L
-
-
- I4
-
-
- L
- 1
-
-
- I4
-
-
- I4
-
-
- C(64)
-
-
- I4
-
-
-
- id
- id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child
- id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child
- id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child
- id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,invoice_delivery,invoice_show_itemized,invoice_grace,invoice_advance_gen,tax_id,max_child
- id,date_orig,date_last,date_expire,parent_id,language_id,country_id,affiliate_id,campaign_id,reseller_id,currency_id,theme_id,username,password,inherit_group,misc,status,first_name,middle_name,last_name,title,email,email_type,company,address1,address2,city,state,zip,tax_id,max_child
- language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
- language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
- language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
- language_id,country_id,affiliate_id,campaign_id,currency_id,username,password,misc,status,first_name,middle_name,last_name,title,email,company,address1,address2,city,state,zip,tax_id
-
-
-
- account_admin:update_account_groups
-
-
-
diff --git a/modules/account_admin/account_admin_install.xml b/modules/account_admin/account_admin_install.xml
deleted file mode 100644
index 1db56c72..00000000
--- a/modules/account_admin/account_admin_install.xml
+++ /dev/null
@@ -1,77 +0,0 @@
-
-
- account_admin
- account_admin
-
- 1
-
-
-
-
- add
- 1
-
-
- update
-
-
- delete
-
-
- view
-
- 1
-
-
- search
-
- 1
-
-
- search_form
-
-
- search_show
-
-
- search_export
-
-
- update_account_groups
-
-
-
- send_verify_email
-
-
-
- send_password_email
-
-
-
- mail_multi
-
-
- mail_one
-
-
- autoselect
-
-
- login
-
-
-
- merge
-
-
-
- group_search
-
-
- product_search
-
-
-
-
-
\ No newline at end of file
diff --git a/modules/account_group/account_group_construct.xml b/modules/account_group/account_group_construct.xml
index e01fc7e9..40732652 100644
--- a/modules/account_group/account_group_construct.xml
+++ b/modules/account_group/account_group_construct.xml
@@ -1,55 +1,59 @@
-
-
- account_group
-
- account
- 0
-
- 25
-
- date_start,date_expire
- active,account_id,group_id
- service_id
-
-
-
- I8
-
-
- I4
- 1
-
-
- I8
-
-
- I8
-
-
- I8
-
-
- I4
- 1
-
-
- I8
- 1
-
-
- I8
-
-
- L
-
-
-
- id,site_id,module_id,name,notes,page,menu_display
- id,site_id,module_id,name,notes,page,menu_display
- id,site_id,module_id,name,notes,page,menu_display
- id,site_id,module_id,name,notes,page,menu_display
- id,site_id,module_id,name,notes,page,menu_display
- id,site_id,module_id,name,notes,page,menu_display
-
- 0
+
+
+ account_group
+
+ account
+ 0
+
+ 25
+
+
+ date_start,date_expire
+ active,account_id,group_id
+ service_id
+
+
+
+
+ I8
+
+
+ I4
+ 1
+
+
+ I8
+
+
+ I8
+
+
+ I8
+
+
+ I4
+ 1
+
+
+ I8
+ 1
+
+
+ I8
+
+
+ L
+
+
+
+
+ id,site_id,module_id,name,notes,page,menu_display
+ id,site_id,module_id,name,notes,page,menu_display
+ id,site_id,module_id,name,notes,page,menu_display
+ id,site_id,module_id,name,notes,page,menu_display
+ id,site_id,module_id,name,notes,page,menu_display
+ id,site_id,module_id,name,notes,page,menu_display
+
+
+ 0
diff --git a/modules/account_group/account_group_install.xml b/modules/account_group/account_group_install.xml
index e73f15d3..e2a19825 100644
--- a/modules/account_group/account_group_install.xml
+++ b/modules/account_group/account_group_install.xml
@@ -1,11 +1,13 @@
account_group
- account_admin
+ account
+ base
+
-
\ No newline at end of file
+
diff --git a/modules/account_group/account_group_install_data.xml b/modules/account_group/account_group_install_data.xml
index 05798359..1406e20a 100644
--- a/modules/account_group/account_group_install_data.xml
+++ b/modules/account_group/account_group_install_data.xml
@@ -1,44 +1,45 @@
-
- 0
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 1
-
-
- 210
- 1
- 1099624291
- 0
- 2
- 1
- 1
-
-
- 211
- 1
- 1099624291
- 0
- 1001
- 1
- 1
-
-
- 212
- 1
- 1099624291
- 0
- 4
- 1
- 1
-
-
- 502
-
-
\ No newline at end of file
+
+ 0
+ 1
+ 0
+ 0
+ 0
+ 0
+ 0
+ 0
+ 1
+
+
+ 210
+ 1
+ 1099624291
+ 0
+ 2
+ 1
+ 1
+
+
+ 211
+ 1
+ 1099624291
+ 0
+ 1001
+ 1
+ 1
+
+
+ 212
+ 1
+ 1099624291
+ 0
+ 4
+ 1
+ 1
+
+
+
+ 502
+
+
diff --git a/modules/account_memo/account_memo.inc.php b/modules/account_memo/account_memo.inc.php
index 6e3a69e0..00005476 100644
--- a/modules/account_memo/account_memo.inc.php
+++ b/modules/account_memo/account_memo.inc.php
@@ -1,125 +1,33 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:Account
*/
-class account_memo
-{
-
- # Open the constructor for this mod
- function account_memo()
- {
- # name of this module:
- $this->module = "account_memo";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
+/**
+ * The main AgileBill Account Memo Class
+ *
+ * @package AgileBill
+ * @subpackage Module:Account
+ */
+class account_memo extends OSB_module {
}
?>
diff --git a/modules/account_memo/account_memo_construct.xml b/modules/account_memo/account_memo_construct.xml
index eebd7367..9819bd6f 100644
--- a/modules/account_memo/account_memo_construct.xml
+++ b/modules/account_memo/account_memo_construct.xml
@@ -1,63 +1,100 @@
-
- account_memo
-
-
-
- account
-
- 0
-
- date_orig
-
- 25
-
-
- account_id
- memo
-
-
-
-
- I8
-
-
- I4
-
-
- I8
- date-time
- date-now
-
-
- I8
- account
- username
-
-
- I8
-
-
- C(32)
- any
-
-
- C(255)
- any
-
-
- C(32)
-
-
-
-
- id,site_id,date_orig,staff_id,account_id,type,memo
- id,site_id,date_orig,staff_id,account_id,type,memo
- id,site_id,date_orig,staff_id,account_id,type,memo
- id,site_id,date_orig,staff_id,account_id,type,memo
- id,site_id,date_orig,staff_id,account_id,type,memo
-
-
- 0
+
+ account_memo
+
+
+
+ account
+
+ 0
+
+ date_orig
+
+ 25
+
+
+
+ account_id
+ memo
+
+
+
+
+ Add Account Memo
+ Account Memo
+
+
+
+
+
+ I8
+
+
+ I4
+
+
+ Date
+ I8
+ date-time
+ date-now
+
+
+ Staff
+ I8
+ account
+ username
+
+
+ Account
+ I8
+
+
+ Type
+ C(32)
+ any
+
+
+ Memo
+ C(255)
+ any
+
+
+ C(32)
+
+
+
+
+
+ date_orig,staff_id,account_id,type,memo
+ id,site_id,date_orig,staff_id,account_id,type,memo
+ id,site_id,date_orig,staff_id,account_id,type,memo
+ id,site_id,date_orig,staff_id,account_id,type,memo
+ id,site_id,date_orig,staff_id,account_id,type,memo
+
+
+
+ 0
+
+
+
+
+
+ id
+ 25px
+
+
+ date_orig
+
+
+ staff_id
+
+
+ type
+
+
+ memo
+
+
+
diff --git a/modules/account_memo/account_memo_install.xml b/modules/account_memo/account_memo_install.xml
index c8469597..3cc0ab1e 100644
--- a/modules/account_memo/account_memo_install.xml
+++ b/modules/account_memo/account_memo_install.xml
@@ -1,10 +1,11 @@
account_memo
- account_admin
-
- invoice
+ account
+
+ account
+
@@ -23,10 +24,10 @@
search
- search_form
+ search_form
- search_show
+ search_show
diff --git a/modules/affiliate/affiliate.inc.php b/modules/affiliate/affiliate.inc.php
index efda6f52..bcb17b4b 100644
--- a/modules/affiliate/affiliate.inc.php
+++ b/modules/affiliate/affiliate.inc.php
@@ -18,37 +18,8 @@
* @version 1.4.93
*/
-class affiliate
-{
- # Open the constructor for this mod
- function affiliate()
- {
- # name of affiliate id prefix
- $this->id_prefix = 'AB-';
-
- # name of this module:
- $this->module = "affiliate";
-
- if(!defined('AJAX'))
- {
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
- }
-
+class affiliate extends OSB_module {
+ private $id_prefix = 'AB-';
###########################################
### AJAX Auto-selector
@@ -858,8 +829,7 @@ class affiliate
##############################
## VIEW ##
##############################
- function view($VAR)
- {
+ function view($VAR) {
$type = "view";
$this->method["$type"] = explode(",", $this->method["$type"]);
@@ -1007,11 +977,8 @@ class affiliate
return;
}
-
-
-
global $smarty;
- $smarty->assign($this->table, $smart);
+ $smarty->assign('record', array_pop($smart));
$smarty->assign('plugin_data', $plugin_data);
$smarty->assign('results', $search->results);
}
@@ -1239,23 +1206,10 @@ class affiliate
}
}
-
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
##############################
## SEARCH ##
##############################
- function search($VAR)
+ function xsearch($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
@@ -1549,7 +1503,7 @@ class affiliate
## SEARCH SHOW ##
##############################
- function search_show($VAR)
+ function xsearch_show($VAR)
{
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
@@ -1803,4 +1757,4 @@ class affiliate
}
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/affiliate/affiliate_construct.xml b/modules/affiliate/affiliate_construct.xml
index fb34ce00..34a60242 100644
--- a/modules/affiliate/affiliate_construct.xml
+++ b/modules/affiliate/affiliate_construct.xml
@@ -1,104 +1,155 @@
-
- affiliate
-
-
-
-
-
- 0
-
- id
-
- 25
-
-
- account_id
- parent_affiliate_id
-
-
-
-
- C(32)
- 1
- 1
-
-
- I4
- 1
-
-
- I8
- date-time
-
-
- I8
- any
- date-now
-
-
- L
-
-
- I8
- any
-
-
- X2
- array
-
-
- C(32)
-
-
- C(16)
- affiliate
- id
-
-
- I4
-
-
- F
-
-
- L
-
-
- X2
- array
-
-
- L
-
-
- X2
- array
-
-
- I4
-
-
- X2
- array
-
-
-
-
- id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
- id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
- id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
- id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
- id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
- date_last,affiliate_plugin,plugin_data
- id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
- id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
- id,date_orig,date_last,status,account_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,recurr_commission_type,recurr_max_commission_periods
- id,date_orig,date_last,status,account_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,recurr_commission_type,recurr_max_commission_periods
- id,date_orig,date_last,status,account_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,recurr_commission_type,recurr_max_commission_periods
- id,date_orig,date_last,status,account_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,recurr_commission_type,recurr_max_commission_periods
-
-
- 0
+
+ affiliate
+
+
+
+
+
+ 0
+
+ id
+
+ 25
+
+ 0
+
+
+
+ account_id
+ parent_affiliate_id
+
+
+
+
+
+
+ 1
+ C(32)
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ date-now
+ Date Updated
+ I8
+
+
+
+ Active
+ L
+
+
+ I8
+ any
+
+
+ X2
+ array
+
+
+ C(32)
+
+
+ C(16)
+ affiliate
+ id
+
+
+ I4
+
+
+ F
+
+
+ L
+
+
+ X2
+ array
+
+
+ L
+
+
+ X2
+ array
+
+
+ I4
+
+
+ X2
+ array
+
+
+
+
+
+ id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
+ id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
+ id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
+ id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
+ id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods,plugin_data
+ date_last,affiliate_plugin,plugin_data
+ id,site_id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
+ id,date_orig,date_last,status,account_id,avail_campaign_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
+ id,date_orig,date_last,status,account_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,recurr_commission_type,recurr_max_commission_periods
+ id,date_orig,date_last,status,account_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,recurr_commission_type,recurr_max_commission_periods
+ id,date_orig,date_last,status,account_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,recurr_commission_type,recurr_max_commission_periods
+ id,date_orig,date_last,status,account_id,affiliate_plugin,parent_affiliate_id,max_tiers,commission_minimum,new_commission_type,recurr_commission_type,recurr_max_commission_periods
+
+
+
+
+
+
+
+ Commissions New Charges
+ Commissions Recurring Charges
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ id
+
+
+ sessions
+
+
+ accounts
+
+
+ invoices
+
+
+ commissions
+
+
+ status
+ 20px
+
+
+
+
+
diff --git a/modules/affiliate/affiliate_install.xml b/modules/affiliate/affiliate_install.xml
index d14e80b6..8908dc41 100644
--- a/modules/affiliate/affiliate_install.xml
+++ b/modules/affiliate/affiliate_install.xml
@@ -1,49 +1,68 @@
+
+
- affiliate
- affiliate
-
+
+
+
+ Affiliates
+
1
+
+ affiliate
+
+
+
+ account
+
affiliate_commission,affiliate_template,campaign
+
+
-
-
-
- search_form
-
-
- search_show
-
-
- search
-
- 1
-
-
- view
-
- 1
-
-
- delete
-
-
- update
-
-
- add
-
- 1
-
-
- search_export
-
-
- mail_multi
-
-
- autoselect
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+ search_export
+
+
+ mail_multi
+
+
+ autoselect
+
+
+
diff --git a/modules/affiliate_commission/affiliate_commission.inc.php b/modules/affiliate_commission/affiliate_commission.inc.php
index c81bf458..b3f2ed5c 100644
--- a/modules/affiliate_commission/affiliate_commission.inc.php
+++ b/modules/affiliate_commission/affiliate_commission.inc.php
@@ -1,50 +1,34 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:AffiliateCommission
*/
-class affiliate_commission
-{
- # Open the constructor for this mod
- function affiliate_commission()
- {
- # name of this module:
- $this->module = "affiliate_commission";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
+/**
+ * The main AgileBill Affilicate Commissions Class
+ *
+ * @package AgileBill
+ * @subpackage Module:AffiliateCommission
+ */
+class affiliate_commission extends OSB_module {
##############################
## ADD ##
##############################
@@ -446,17 +430,6 @@ class affiliate_commission
}
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
##############################
## DELETE ##
##############################
@@ -494,38 +467,5 @@ class affiliate_commission
$result = $db->Execute($sql);
}
}
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/affiliate_commission/affiliate_commission_construct.xml b/modules/affiliate_commission/affiliate_commission_construct.xml
index d4ce2b57..13064f7f 100644
--- a/modules/affiliate_commission/affiliate_commission_construct.xml
+++ b/modules/affiliate_commission/affiliate_commission_construct.xml
@@ -1,66 +1,113 @@
-
- affiliate_commission
-
-
-
- affiliate
-
- 0
-
- date_orig
-
- 25
-
-
- date_begin
- date_end
-
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- I8
- date-now
-
-
- I8
- date
-
-
- I8
- date
-
-
- F
-
-
- X2
-
-
- X2
-
-
- L
-
-
-
-
- id,site_id,date_orig,date_begin,date_end,commissions,notes_admin,notes_affiliate,status
- id,site_id,date_orig,date_begin,date_end,commissions,notes_admin,notes_affiliate,status
- id,site_id
- id,site_id,date_orig,date_begin,date_end,commissions,notes_admin,notes_affiliate,status
- id,site_id,date_orig,date_begin,date_end,commissions,notes_admin,notes_affiliate,status
-
-
- 0
+
+ affiliate_commission
+
+
+
+ affiliate
+
+ 0
+
+ date_orig
+
+ 25
+
+ 0
+
+
+
+ date_begin
+ date_end
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ Active
+ L
+
+
+ date
+ I8
+
+
+ I8
+ date
+
+
+ F
+
+
+ X2
+
+
+ X2
+
+
+
+
+
+ id,site_id,date_orig,date_begin,date_end,commissions,notes_admin,notes_affiliate,status
+ id,site_id,date_orig,date_begin,date_end,commissions,notes_admin,notes_affiliate,status
+ id,site_id
+ id,site_id,date_orig,date_begin,date_end,commissions,notes_admin,notes_affiliate,status
+ id,site_id,date_orig,date_begin,date_end,commissions,notes_admin,notes_affiliate,status
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ date_orig
+ date
+
+
+ date_begin
+ date
+
+
+ date_end
+ date
+
+
+ commissions
+
+
+ status
+ bool_icon
+ 20px
+
+
+
diff --git a/modules/affiliate_commission/affiliate_commission_install.xml b/modules/affiliate_commission/affiliate_commission_install.xml
index 6cd1e34a..ca36588d 100644
--- a/modules/affiliate_commission/affiliate_commission_install.xml
+++ b/modules/affiliate_commission/affiliate_commission_install.xml
@@ -1,41 +1,62 @@
+
+
- affiliate_commission
- affiliate
-
- 1
+
affiliate
+
+ Affiliate Commissions
+
+ 1
+
+ affiliate_commission
+
+
+
+ affiliate
+
+
+
+
-
-
-
- add
-
- 1
-
-
- update
-
-
- delete
-
-
- view
-
-
- search
-
- 1
-
-
- search_form
-
-
- search_show
-
-
- export
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+ export
+
+
+
diff --git a/modules/affiliate_template/affiliate_template.inc.php b/modules/affiliate_template/affiliate_template.inc.php
index 5b25baef..a5369346 100644
--- a/modules/affiliate_template/affiliate_template.inc.php
+++ b/modules/affiliate_template/affiliate_template.inc.php
@@ -1,125 +1,33 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:AffiliateTemplate
*/
-class affiliate_template
-{
-
- # Open the constructor for this mod
- function affiliate_template()
- {
- # name of this module:
- $this->module = "affiliate_template";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
+/**
+ * The main AgileBill Module:Affiliate Template Class
+ *
+ * @package AgileBill
+ * @subpackage Module:AffiliateTemplate
+ */
+class affiliate_template extends OSB_module {
}
?>
diff --git a/modules/affiliate_template/affiliate_template_construct.xml b/modules/affiliate_template/affiliate_template_construct.xml
index 34a90956..bb6198e3 100644
--- a/modules/affiliate_template/affiliate_template_construct.xml
+++ b/modules/affiliate_template/affiliate_template_construct.xml
@@ -1,85 +1,127 @@
-
- affiliate_template
-
-
-
- affiliate
-
- 0
-
- name
-
- 25
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- C(32)
-
-
- X2
- array
-
-
- L
-
-
- C(32)
- 2
- 32
- any
-
-
- X2
-
-
- I4
- 1
- 2
- numeric
-
-
- F
- 1
- 12
- float
-
-
- L
-
-
- X2
- array
-
-
- L
-
-
- X2
- array
-
-
- I4
-
-
-
-
- id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
- id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
- id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
- id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
- id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
-
-
- 0
+
+ affiliate_template
+
+
+
+ affiliate
+
+ 0
+
+ name
+
+ 25
+
+ 0
+
+
+
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ Active
+ L
+
+
+ C(32)
+
+
+ X2
+ array
+
+
+ C(32)
+ 2
+ 32
+ any
+
+
+ X2
+
+
+ I4
+ 1
+ 2
+ numeric
+
+
+ F
+ 1
+ 12
+ float
+
+
+ L
+
+
+ X2
+ array
+
+
+ L
+
+
+ X2
+ array
+
+
+ I4
+
+
+
+
+
+ affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
+ id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
+ id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
+ id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
+ id,site_id,affiliate_plugin,avail_campaign_id,status,name,notes,max_tiers,commission_minimum,new_commission_type,new_commission_rate,recurr_commission_type,recurr_commission_rate,recurr_max_commission_periods
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ name
+
+
+ max_tiers
+
+
+ commission_minimum
+
+
+ status
+ bool_icon
+ 20px
+
+
+
diff --git a/modules/affiliate_template/affiliate_template_install.xml b/modules/affiliate_template/affiliate_template_install.xml
index edd2e2f6..1bf4de8b 100644
--- a/modules/affiliate_template/affiliate_template_install.xml
+++ b/modules/affiliate_template/affiliate_template_install.xml
@@ -1,35 +1,55 @@
+
+
- affiliate_template
- affiliate
-
- 1
+
affiliate
+
+ Affiliate Templates
+
+ 1
+
+ affiliate_template
+
+
+
+ affiliate
+
+
+
+
-
-
-
- delete
-
-
- view
-
- 1
-
-
- update
-
-
- add
-
- 1
-
-
- search
-
-
- search_show
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/affiliate_template/affiliate_template_install_data.xml b/modules/affiliate_template/affiliate_template_install_data.xml
index f8be3d1d..feae42d7 100644
--- a/modules/affiliate_template/affiliate_template_install_data.xml
+++ b/modules/affiliate_template/affiliate_template_install_data.xml
@@ -1,21 +1,21 @@
-
- 1
- 1
- ACCOUNT_DISCOUNT
-
- 1
- Default
- 1
- 10
- 1
-
- 1
-
- 5
-
-
- 1
-
-
\ No newline at end of file
+
+ 1
+ 1
+ ACCOUNT_DISCOUNT
+
+ 1
+ Default
+ 1
+ 10
+ 1
+
+ 1
+
+ 5
+
+
+ 1
+
+
diff --git a/modules/blocked_email/blocked_email.inc.php b/modules/blocked_email/blocked_email.inc.php
index ceec3970..518b0c74 100644
--- a/modules/blocked_email/blocked_email.inc.php
+++ b/modules/blocked_email/blocked_email.inc.php
@@ -1,146 +1,48 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:BlockedEmail
*/
-class blocked_email
-{
+/**
+ * The main AgileBill Blocked Email Class
+ *
+ * @package AgileBill
+ * @subpackage Module:BlockedEmail
+ */
+class blocked_email extends OSB_module {
+ /**
+ * Is Email Blocked?
+ */
+ public function is_blocked($email) {
+ if ($email && ! preg_match('/@/',$email))
+ return true;
- # Open the constructor for this mod
- function blocked_email()
- {
- # name of this module:
- $this->module = "blocked_email";
+ $dom = explode('@',$email);
+ $db = &DB();
+ $result = $db->Execute(sqlSelect($db,'blocked_email','id',sprintf('email=::%s:: OR email=::%s::',$email,$dom[1])));
+ if ($result && $result->RecordCount() > 0)
+ return true;
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
+ return false;
}
-
-
- ##############################
- ## IS EMAIL BLOCKED? ##
- ##############################
- function is_blocked($email)
- {
- @$dom = explode('@', $email);
- $db = &DB();
- $sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'blocked_email WHERE
- email = ' . $db->qstr($email) .' OR
- email = ' . $db->qstr($dom[1]) .' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
- if($result->RecordCount() > 0)
- {
- return false;
- }
- return true;
- }
-
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/blocked_email/blocked_email_construct.xml b/modules/blocked_email/blocked_email_construct.xml
index c3ae6841..f4580df9 100644
--- a/modules/blocked_email/blocked_email_construct.xml
+++ b/modules/blocked_email/blocked_email_construct.xml
@@ -1,59 +1,95 @@
-
- blocked_email
-
-
-
-
-
- 0
-
- email
-
- 25
-
-
- email
-
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- I8
- date-now
-
-
- I8
- date-now
-
-
- C(128)
- 1
- 128
- any
-
-
- X2
-
-
-
-
- id,site_id,date_orig,date_last,email,notes
- id,site_id,date_orig,date_last,email,notes
- id,site_id,date_orig,date_last,email,notes
- id,site_id,date_orig,date_last,email,notes
- id,site_id,date_orig,date_last,email,notes
-
-
-
-
+
+ blocked_email
+
+
+
+
+
+ 0
+
+ email
+
+ 25
+
+ 1
+
+
+
+ email
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ date-now
+ Date Updated
+ I8
+
+
+ Email
+ C(128)
+ 1
+ 128
+ any
+ 1
+
+
+ X2
+
+
+
+
+
+ date_orig,date_last,email,notes
+ id,site_id,date_orig,date_last,email,notes
+ id,site_id,date_orig,date_last,email,notes
+ id,site_id,date_orig,date_last,email,notes
+ id,site_id,date_orig,date_last,email,notes
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ date_orig
+ date
+ 150px
+
+
+ email
+
+
+
diff --git a/modules/blocked_email/blocked_email_install.xml b/modules/blocked_email/blocked_email_install.xml
index 2cd5a4c7..23d66f4c 100644
--- a/modules/blocked_email/blocked_email_install.xml
+++ b/modules/blocked_email/blocked_email_install.xml
@@ -1,42 +1,59 @@
+
+
- blocked_email
- setup
-
+
+
+
+ Blocked Email
+
1
+
+ blocked_email
+
+
+
+ setup
+
+
+
+ base
-
-
-
- search
-
-
- 1
-
-
- view
-
-
- 1
-
-
- add
-
- 1
-
-
- delete
-
-
- update
-
-
- search_form
-
-
- search_show
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/blocked_ip/blocked_ip.inc.php b/modules/blocked_ip/blocked_ip.inc.php
index 782c9c18..d1519d2b 100644
--- a/modules/blocked_ip/blocked_ip.inc.php
+++ b/modules/blocked_ip/blocked_ip.inc.php
@@ -1,146 +1,50 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:BlockedIP
*/
-class blocked_ip
-{
+/**
+ * The main AgileBill Blocked IP Class
+ *
+ * @package AgileBill
+ * @subpackage Module:BlockedIP
+ */
+class blocked_ip extends OSB_module {
+ /**
+ * Is IP Blocked?
+ */
+ public function is_blocked($ip) {
+ if ($ip && ! preg_match('/\./',$ip))
+ return true;
- # Open the constructor for this mod
- function blocked_ip()
- {
- # name of this module:
- $this->module = "blocked_ip";
+ $ip_oct = explode('.',$ip);
+ $db = &DB();
+ $result = $db->Execute($q=sqlSelect($db,'blocked_ip','id',sprintf('ip IN (::%s::,::%s.%s::,::%s.%s.%s::,::%s::)',
+ $ip_oct[0],$ip_oct[0],@$ip_oct[1],$ip_oct[0],@$ip_oct[1],@$ip_oct[2],$ip)));
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
+ if ($result->RecordCount() > 0)
+ return true;
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
+ return false;
}
-
- ##############################
- ## IS IP BLOCKED? ##
- ##############################
- function is_blocked($ip)
- {
- $ip_full = $ip;
- @$ip = explode('\.', $ip_full);
- $db = &DB();
- $sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'blocked_ip WHERE
- ip = ' . $db->qstr(@$ip[0]) . ' OR
- ip = ' . $db->qstr(@$ip[0].'.'.@$ip[1]) . ' OR
- ip = ' . $db->qstr(@$ip[0].'.'.@$ip[1].'.'.@$ip[2]) . ' OR
- ip = ' . $db->qstr($ip_full) . ' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
- if($result->RecordCount() > 0)
- {
- return false;
- }
- return true;
- }
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/blocked_ip/blocked_ip_construct.xml b/modules/blocked_ip/blocked_ip_construct.xml
index 8eea0590..908d871e 100644
--- a/modules/blocked_ip/blocked_ip_construct.xml
+++ b/modules/blocked_ip/blocked_ip_construct.xml
@@ -1,57 +1,95 @@
-
- blocked_ip
-
-
-
-
-
- 0
-
- ip
-
- 25
-
-
- ip
-
-
-
-
- I4
- 1
-
-
- I4
- 1
-
-
- I8
- date-time
-
-
- I8
-
-
- C(128)
- 1
- 128
- any
-
-
- X2
-
-
-
-
- id,site_id,date_orig,date_last,ip,notes
- id,site_id,date_orig,date_last,ip,notes
- id,site_id,date_orig,date_last,ip,notes
- id,site_id,date_orig,date_last,ip,notes
- id,site_id,date_orig,date_last,ip,notes
-
-
-
-
+
+ blocked_ip
+
+
+
+
+
+ 0
+
+ ip
+
+ 25
+
+ 1
+
+
+
+ ip
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ date-now
+ Date Updated
+ I8
+
+
+ IP Address
+ C(128)
+ 1
+ 128
+ any
+ 1
+
+
+ X2
+
+
+
+
+
+ date_orig,date_last,ip,notes
+ id,site_id,date_orig,date_last,ip,notes
+ id,site_id,date_orig,date_last,ip,notes
+ id,site_id,date_orig,date_last,ip,notes
+ id,site_id,date_orig,date_last,ip,notes
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ date_orig
+ date
+ 150px
+
+
+ ip
+
+
+
diff --git a/modules/blocked_ip/blocked_ip_install.xml b/modules/blocked_ip/blocked_ip_install.xml
index ce97c4a4..512860aa 100644
--- a/modules/blocked_ip/blocked_ip_install.xml
+++ b/modules/blocked_ip/blocked_ip_install.xml
@@ -1,42 +1,59 @@
+
+
- blocked_ip
- setup
-
+
+
+
+ Blocked IP
+
1
+
+ blocked_ip
+
+
+
+ setup
+
+
+
+ base
-
-
-
- search
-
-
- 1
-
-
- view
-
-
- 1
-
-
- add
-
- 1
-
-
- delete
-
-
- update
-
-
- search_form
-
-
- search_show
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/campaign/campaign.inc.php b/modules/campaign/campaign.inc.php
index 67a1b7a8..02ce8e23 100644
--- a/modules/campaign/campaign.inc.php
+++ b/modules/campaign/campaign.inc.php
@@ -6,49 +6,24 @@
* This body of work is free software; you can redistribute it and/or
* modify it under the terms of the Open AgileBill License
* License as published at http://www.agileco.com/agilebill/license1-4.txt
- *
+ *
* For questions, help, comments, discussion, etc., please join the
- * Agileco community forums at http://forum.agileco.com/
+ * Agileco community forums at http://forum.agileco.com/
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
* @version 1.4.93
*/
-
-class campaign
-{
- # Open the constructor for this mod
- function campaign()
- {
- # name of this module:
- $this->module = "campaign";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
+class campaign extends OSB_module {
##############################
## CLICK ##
##############################
function click($VAR)
- {
+ {
### Set the forward URL
if(!empty($VAR['caid']))
{
@@ -56,9 +31,9 @@ class campaign
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'campaign WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
id = ' . $db->qstr(@$VAR['caid']);
- $result = $db->Execute($sql);
+ $result = $db->Execute($sql);
if (strlen($result->fields['url']) >= 1) $url = $result->fields['url'];
- }
+ }
if(empty($url)) $url = URL;
echo '';
+
+ # Validate user is logged in:
+ if (! SESS_LOGGED) {
+ printf('',
+ _('You must be logged in to complete this purchase! Please refresh this page in your browser to login now.'));
+
return false;
}
-
- // check for admin
- if(!$this->admin_checkout && !empty($VAR['account_id'])) {
+
+ # Check for admin
+ if (! $this->admin_checkout && ! empty($VAR['account_id'])) {
global $C_auth;
- if(!empty($VAR['account_id']) && $C_auth->auth_method_by_name('checkout','admin_checkoutnow')) {
- $this->account_id=$VAR['account_id'];
- $this->admin_checkout=true;
+
+ if (! empty($VAR['account_id']) && $C_auth->auth_method_by_name('checkout','admin_checkoutnow')) {
+ $this->account_id = $VAR['account_id'];
+ $this->admin_checkout = true;
+
} else {
- $this->account_id=SESS_ACCOUNT;
- }
+ $this->account_id = SESS_ACCOUNT;
+ }
}
-
- if(empty($this->session_id)) $this->session_id = SESS;
- if(empty($this->account_id)) $this->account_id = SESS_ACCOUNT;
-
- include_once ( PATH_MODULES . '/cart/cart.inc.php' );
+
+ if (empty($this->session_id))
+ $this->session_id = SESS;
+ if (empty($this->account_id))
+ $this->account_id = SESS_ACCOUNT;
+
+ include_once(PATH_MODULES.'/cart/cart.inc.php');
$cartObj = new cart;
- $cartObj->account_id=$this->account_id;
- $cartObj->session_id=$this->session_id;
- $result = $cartObj->get_contents($db);
- if($result->RecordCount() == 0) return false;
-
- // load invoice object
+
+ $cartObj->account_id = $this->account_id;
+ $cartObj->session_id = $this->session_id;
+ $result = $cartObj->get_contents();
+ if (! $result || $result->RecordCount() == 0)
+ return false;
+
+ # Load invoice object
include_once(PATH_MODULES.'invoice/invoice.inc.php');
$invoice = new invoice;
+
+ $invoice->initNew(0);
$invoice->account_id = $this->account_id;
- $invoice->initNew(0);
-
- // Get the account details:
- $account = $db->Execute(sqlSelect($db,"account","*","id=::$this->account_id::"));
+
+ # Get the account details:
+ $account = $db->Execute(sqlSelect($db,'account','*',array('id'=>$this->account_id)));
$invoice->country_id = $account->fields['country_id'];
$invoice->state = $account->fields['state'];
- // load tax object for tax calculation
- include_once(PATH_MODULES.'tax/tax.inc.php');
- $taxObj=new tax;
-
- // load discount object for discount calculation
- include_once(PATH_MODULES.'discount/discount.inc.php');
- $discountObj=new discount;
- $discountObj->available_discounts($invoice->account_id);
-
- // put cart contents into invoice format
- $cartObj->put_contents_invoice($db, $result, $invoice, $smart, $taxObj, $discountObj);
-
+ # Put cart contents into invoice format
+ $cartObj->put_contents_invoice($result,$invoice);
+
// Validate and init a checkout plugin
- $checkout=false;
- if($this->admin_checkout_option) {
- // admin checkout option specified
- include_once ( PATH_MODULES . 'checkout/checkout_admin.inc.php' );
- $PLG = new checkout_admin;
- $checkout=true;
- $invoice->checkout_plugin_id=false;
- } else {
- // get available checkout options and check against the one provided
- $invoice->checkout_plugin_id=$VAR['option'];
- foreach($invoice->invoice_item as $item) if(!empty($item['product_id'])) $product_arr[]=$item['product_id'];
- $checkout_options = $this->get_checkout_options($this->account_id,$invoice->total_amt,@$product_arr,$invoice->country_id,$invoice->any_new, $invoice->any_trial, $invoice->any_recurring);
- if($checkout_options) {
- foreach($checkout_options as $a) {
- if($a['fields']['id']==$invoice->checkout_plugin_id) {
- // load the selected checkout plugin and run pre-validation
- $checkout_plugin=$a['fields']['checkout_plugin'];
- $plugin_file = PATH_PLUGINS . 'checkout/'.$checkout_plugin.'.php';
- include_once ( $plugin_file );
- eval ( '$PLG = new plg_chout_'.$checkout_plugin.'("'.$invoice->checkout_plugin_id.'");');
- $plugin_validate = $PLG->validate($VAR, $this);
- if ( $plugin_validate != true ) {
+ $checkout = false;
+ if ($this->admin_checkout_option) {
+ # Admin checkout option specified
+ include_once(PATH_MODULES.'checkout/checkout_admin.inc.php');
+ $PLG = new checkout_admin;
+
+ $checkout = true;
+ $invoice->checkout_plugin_id = false;
+
+ } else {
+ // Get available checkout options and check against the one provided
+ $invoice->checkout_plugin_id = $VAR['option'];
+ $product_arr = array();
+ foreach ($invoice->invoice_item as $item)
+ if (! empty($item['product_id']))
+ array_push($product_arr,$item['product_id']);
+
+ $checkout_options = $this->get_checkout_options($this->account_id,$invoice->total_amt,$product_arr,$invoice->country_id,$invoice->any_new,$invoice->any_trial,$invoice->any_recurring);
+ if ($checkout_options) {
+ foreach ($checkout_options as $a) {
+ if ($a['fields']['id'] == $invoice->checkout_plugin_id) {
+ # Load the selected checkout plugin and run pre-validation
+ $checkout_plugin = $a['fields']['checkout_plugin'];
+ include_once(sprintf('%scheckout/%s.php',PATH_PLUGINS,$checkout_plugin));
+ eval ('$PLG = new plg_chout_'.$checkout_plugin.'("'.$invoice->checkout_plugin_id.'");');
+
+ $plugin_validate = $PLG->validate($VAR,$this);
+ if ($plugin_validate != true) {
echo $plugin_validate;
return false;
- }
+ }
+
$checkout=true;
break;
}
}
- }
+ }
}
- if(!$checkout) {
+
+ if (! $checkout) {
echo ' ';
return false;
}
-
+
// validate credit card on file details
- global $VAR;
- if(!empty($VAR['account_billing_id']) && @$VAR['new_card']==2) {
- $invoice->account_billing_id=$VAR['account_billing_id'];
- /* validate credit card on file details */
- if(!$PLG->setBillingFromDB($this->account_id, $invoice->account_billing_id, $invoice->checkout_plugin_id)) {
+ global $VAR;
+ if (! empty($VAR['account_billing_id']) && @$VAR['new_card']==2) {
+ $invoice->account_billing_id=$VAR['account_billing_id'];
+ /* validate credit card on file details */
+ if(!$PLG->setBillingFromDB($this->account_id, $invoice->account_billing_id, $invoice->checkout_plugin_id)) {
global $C_debug;
$C_debug->alert("Sorry, we cannot use that billing record for this purchase.");
return false;
}
+
} else {
/* use passed in vars */
$PLG->setBillingFromParams($VAR);
- }
-
+ }
+
// validate recurring processing options
if ($PLG->recurr_only) {
if ($invoice->recur_amt<=0) {
echo ' ';
return false;
}
+
if(is_array($invoice->recur_arr) && count($invoice->recur_arr)>1) {
$recurring = true;
// validate recur day and recurring schedule are the same for both products
- foreach($invoice->recur_arr as $a) {
- foreach($invoice->recur_arr as $b) {
- foreach($b as $key=>$val) {
+ foreach($invoice->recur_arr as $a) {
+ foreach($invoice->recur_arr as $b) {
+ foreach($b as $key=>$val) {
if($key != 'price' && $key != 'recurr_week' && $a[$key] != $val) {
$recurring=false;
break;
}
}
}
- }
+ }
if (!$recurring) {
echo ' ';
return false;
}
}
}
-
+
# Affiliate
if(empty($this->affiliate_id)) {
if(!empty($account->fields['affiliate_id']))
@@ -439,15 +457,15 @@ class checkout
else
$invoice->campaign_id = SESS_CAMPAIGN;
}
-
- $invoice->record_id = sqlGenID($db,"invoice");
+
+ $invoice->record_id = sqlGenID($db,"invoice");
$invoice->actual_billed_currency_id = SESS_CURRENCY;
$invoice->billed_currency_id = DEFAULT_CURRENCY;
$invoice->checkout_type = $PLG->type;
-
+
// initial invoice status
if( $invoice->total_amt == 0 || $PLG->type == 'gateway') {
- $invoice->billing_status = 1;
+ $invoice->billing_status = 1;
$invoice->actual_billed_amt = $C_list->format_currency_decimal($invoice->total_amt, SESS_CURRENCY);
$invoice->billed_amt = $invoice->total_amt;
}
@@ -460,7 +478,7 @@ class checkout
$bill_amt = round($invoice->total_amt,2);
$recur_amt = round($invoice->recur_amt,2);
}
-
+
// Get currency ISO (three_digit) for checkout plugin
$currrs = $db->Execute(sqlSelect($db,"currency","three_digit","id=".SESS_CURRENCY));
if($currrs && $currrs->RecordCount()) $currency_iso = $currrs->fields['three_digit'];
@@ -470,12 +488,12 @@ class checkout
$invoice->checkout_plugin_data = $PLG->bill_checkout($bill_amt, $invoice->record_id, $currency_iso, $account->fields, $recur_amt, $invoice->recur_arr);
if($invoice->checkout_plugin_data === false || $invoice->checkout_plugin_data == '' ) {
if(!empty($PLG->redirect)) echo $PLG->redirect;
- return false;
+ return false;
} elseif ($PLG->type == "gateway" || empty($PLG->redirect)) {
- $VAR['id'] = $invoice->record_id;
- if(!$this->admin_checkout) $VAR['_page'] = "invoice:thankyou";
- $invoice->checkout_plugin_data=false;
- } elseif(!$this->admin_checkout) {
+ $VAR['id'] = $invoice->record_id;
+ if(!$this->admin_checkout) $VAR['_page'] = "invoice:thankyou";
+ $invoice->checkout_plugin_data=false;
+ } elseif(!$this->admin_checkout) {
echo "
Please wait while we redirect you to the secure payment site....
{$PLG->redirect} ";
@@ -483,36 +501,36 @@ class checkout
// Call the Plugin method for storing the checkout data:
$invoice->account_billing_id = $PLG->store_billing($VAR, $invoice->account_id);
-
- // clear user discounts
+
+ // clear user discounts
$fields=Array('discounts'=>"");
$db->Execute(sqlUpdate($db,"session",$fields,"id = ::".SESS."::"));
-
+
// admin options
$email=true;
- if($this->admin_checkout) {
+ if($this->admin_checkout) {
if(empty($VAR['send_email']) || $VAR['send_email']=='false') $email=false; else $email=true;
if(!empty($VAR['due_date'])) $invoice->due_date=$this->getInputDate($VAR['due_date']);
if(!empty($VAR['grace_period'])) $invoice->grace_period=$VAR['grace_period'];
- if(!empty($VAR['notice_max'])) $invoice->notice_max=$VAR['notice_max'];
+ if(!empty($VAR['notice_max'])) $invoice->notice_max=$VAR['notice_max'];
}
-
- if($invoice->commitNew($taxObj, $discountObj, $email)) {
- // delete all cart items
- $db->Execute(sqlDelete($db,"cart", "(session_id=::".SESS.":: OR account_id=$invoice->account_id)"));
- // admin redirect
- if($this->admin_checkout) {
- $url = URL.'admin.php?_page=invoice:view&id='.$invoice->record_id;
- echo '';
- }
- }
- return false;
+
+ if ($invoice->commitNew($taxObj,$discountObj,$email)) {
+ # Delete all cart items
+ $db->Execute(sqlDelete($db,'cart',sprintf('(session_id=::%s:: OR account_id=%s)',SESS,$invoice->account_id)));
+
+ # Admin redirect
+ if ($this->admin_checkout)
+ printf('',URL,$invoice->record_id);
+ }
+
+ return false;
}
- /** Convert a localized d,m,y string to epoch timestamp
+ /** Convert a localized d,m,y string to epoch timestamp
*/
- function getInputDate($date) {
-
+ function getInputDate($date) {
+
$Arr_format = explode(DEFAULT_DATE_DIVIDER, UNIX_DATE_FORMAT);
$Arr_date = explode(DEFAULT_DATE_DIVIDER, $date);
for($i=0; $i<3; $i++)
@@ -522,26 +540,26 @@ class checkout
if($Arr_format[$i] == 'Y') $year = $Arr_date[$i];
}
$timestamp = mktime(0, 0, 0, $month, $day, $year);
- return $timestamp;
-
+ return $timestamp;
+
return time();
}
-
+
/**
- * Manage postback for multiple invoices
+ * Manage postback for multiple invoices
*/
function postback_multiple($arr) {
$db=&DB();
include_once(PATH_MODULES.'invoice/invoice.inc.php');
- $invoice=new invoice;
-
+ $invoice=new invoice;
+
// get multi-invoice details
$total = $invoice->multiple_invoice_total($arr['invoice_id']);
- if(!$total) return false;
-
+ if(!$total) return false;
+
$amt = $arr['amount'];
-
- foreach($invoice->invoice_id as $id)
+
+ foreach($invoice->invoice_id as $id)
{
if($amt > 0)
{
@@ -549,56 +567,56 @@ class checkout
$rs=sqlSelect($db, "invoice","SUM(total_amt-billed_amt) as total","id=$id");
if($rs && $rs->RecordCount()) {
$thisamt = $rs->fields["total"];
-
+
if($thisamt > $amt)
$arr['amount'] = $amt;
else
$arr['amount'] = $thisamt;
$arr["invoice_id"] = $id;
-
+
$this->postback($arr);
$amt -= $thisamt;
}
- }
- }
+ }
+ }
}
-
+
/**
- * Postback for Redirect Pay
+ * Postback for Redirect Pay
*/
function postback($arr)
{
global $C_debug;
-
- if(empty($arr['invoice_id'])) return false;
- if(empty($arr['transaction_id'])) return false;
+
+ if(empty($arr['invoice_id'])) return false;
+ if(empty($arr['transaction_id'])) return false;
if(empty($arr['amount'])) return false;
-
+
if(eregi("MULTI-", $arr['invoice_id'])) {
$this->postback_multiple($arr);
return;
}
# Get the latest invoice info:
- $db = &DB();
+ $db = &DB();
$sql1 ="";
if(!empty($arr['subscription_id']))
$sql1 = "checkout_plugin_data = ".$db->qstr( trim($arr['subscription_id']) )." OR ";
$q = "SELECT * FROM ".AGILE_DB_PREFIX."invoice WHERE
- (
+ (
$sql1
parent_id = ".$db->qstr(@$arr['invoice_id'])."
OR
- id = ".$db->qstr(@$arr['invoice_id'])."
- )
+ id = ".$db->qstr(@$arr['invoice_id'])."
+ )
AND
billing_status != 1
- AND
+ AND
site_id = ".$db->qstr(DEFAULT_SITE)."
ORDER BY date_orig
- LIMIT 0,1";
+ LIMIT 0,1";
$invoice = $db->Execute($q);
if ($invoice === false || $invoice->RecordCount()==0)
@@ -706,7 +724,7 @@ class checkout
invoice_id = ".$db->qstr($invoice_id)." AND
type = ".$db->qstr('postback')." AND
memo = ".$db->qstr($arr['transaction_id'])." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
+ site_id = ".$db->qstr(DEFAULT_SITE);
$memo = $db->Execute($q);
if ($memo === false)
@@ -719,14 +737,14 @@ class checkout
# Create the invoice memo:
$memo_id = $db->GenID(AGILE_DB_PREFIX . 'invoice_memo_id');
$q = "INSERT INTO
- ".AGILE_DB_PREFIX."invoice_memo
+ ".AGILE_DB_PREFIX."invoice_memo
SET
id = ".$db->qstr($memo_id).",
site_id = ".$db->qstr(DEFAULT_SITE).",
- date_orig = ".$db->qstr(time()).",
- invoice_id = ".$db->qstr($invoice_id).",
- account_id = ".$db->qstr(0).",
- type = ".$db->qstr('postback').",
+ date_orig = ".$db->qstr(time()).",
+ invoice_id = ".$db->qstr($invoice_id).",
+ account_id = ".$db->qstr(0).",
+ type = ".$db->qstr('postback').",
memo = ".$db->qstr($arr['transaction_id']) ;
$memosql = $db->Execute($q);
@@ -735,14 +753,14 @@ class checkout
# Update the invoice billing info:
$q = "UPDATE
- ".AGILE_DB_PREFIX."invoice
+ ".AGILE_DB_PREFIX."invoice
SET
- date_last = ".$db->qstr(time()).",
- billing_status = ".$db->qstr($this->billing_status).",
- checkout_plugin_id = ".$db->qstr($this->checkout_id).",
- checkout_plugin_data = ".$db->qstr($this->subscription_id).",
- billed_amt = ".$db->qstr($this->billed_amt).",
- actual_billed_amt = ".$db->qstr($this->actual_billed_amt).",
+ date_last = ".$db->qstr(time()).",
+ billing_status = ".$db->qstr($this->billing_status).",
+ checkout_plugin_id = ".$db->qstr($this->checkout_id).",
+ checkout_plugin_data = ".$db->qstr($this->subscription_id).",
+ billed_amt = ".$db->qstr($this->billed_amt).",
+ actual_billed_amt = ".$db->qstr($this->actual_billed_amt).",
actual_billed_currency_id = ".$db->qstr($this->actual_billed_currency_id)."
WHERE
id = ".$db->qstr($invoice_id)." AND
@@ -764,14 +782,14 @@ class checkout
# create a record of the viod in an invoice memo:
$memo_id = $db->GenID(AGILE_DB_PREFIX . 'invoice_memo_id');
$q = "INSERT INTO
- ".AGILE_DB_PREFIX."invoice_memo
+ ".AGILE_DB_PREFIX."invoice_memo
SET
id = ".$db->qstr($memo_id).",
site_id = ".$db->qstr(DEFAULT_SITE).",
- date_orig = ".$db->qstr(time()).",
- invoice_id = ".$db->qstr($invoice_id).",
- account_id = ".$db->qstr(0).",
- type = ".$db->qstr('void').",
+ date_orig = ".$db->qstr(time()).",
+ invoice_id = ".$db->qstr($invoice_id).",
+ account_id = ".$db->qstr(0).",
+ type = ".$db->qstr('void').",
memo = ".$db->qstr("Voided due to postback: ".$arr['transaction_id']) ;
$rsql = $db->Execute($q);
@@ -797,109 +815,55 @@ class checkout
}
/**
- * Display Checkout Data Form
+ * Display Checkout Data Form
*/
function checkoutoption($VAR) {
- global $VAR, $C_translate, $smarty;
+ global $VAR,$C_translate,$C_auth,$C_vars,$smarty;
- if(SESS_LOGGED != '1') {
- $smarty->assign('plugin_template', false);
+ if (SESS_LOGGED != '1') {
+ $smarty->assign('plugin_template',false);
return false;
}
- // Normal checkout
+ # Normal checkout
$db = &DB();
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."checkout WHERE site_id=".DEFAULT_SITE." AND id=".$db->qstr(@$VAR["option"]);
- $rs = $db->Execute($q);
- if($rs == false || $rs->RecordCount() == 0) {
- $smarty->assign('plugin_template', false);
+ $rs = $db->Execute(sqlSelect($db,'checkout','*',array('id'=>$VAR['option'])));
+ if (! $rs || $rs->RecordCount() == 0) {
+ $smarty->assign('plugin_template',false);
return false;
}
-
- // determine account id
- global $C_auth;
- if(!empty($VAR['account_id']) && $C_auth->auth_method_by_name('checkout','admin_checkoutnow')) {
- $this->account_id=$VAR['account_id'];
- $this->admin_view = true;
- } else {
- $this->account_id=SESS_ACCOUNT;
- }
-
- // Set account options && seed VAR with defaults
- if(empty($VAR['detailsnocopy'])) {
- $acct = $db->Execute($sql=sqlSelect($db,"account","first_name,last_name,address1,address2,city,state,zip,country_id,email,company","id=".$this->account_id));
- if($acct && $acct->RecordCount())
- foreach($acct->fields as $key=>$val)
- if(!is_numeric($key) && empty($VAR["$key"]))
- $VAR["$key"]=stripslashes($acct->fields["$key"]);
- }
-
- global $C_vars;
- $C_vars->strip_slashes_all();
- $smarty->assign('VAR', $VAR);
-
- $smarty->assign('plugin_template', 'checkout_plugin:plugin_ord_' . $rs->fields["checkout_plugin"]);
+
+ # Determine account id
+ if (! empty($VAR['account_id']) && $C_auth->auth_method_by_name('checkout','admin_checkoutnow')) {
+ $this->account_id = $VAR['account_id'];
+ $this->admin_view = true;
+ } else {
+ $this->account_id=SESS_ACCOUNT;
+ }
+
+ # Set account options && seed VAR with defaults
+ if (empty($VAR['detailsnocopy'])) {
+ $acct = $db->Execute(sqlSelect($db,'account','first_name,last_name,address1,address2,city,state,zip,country_id,email,company',array('id'=>$this->account_id)));
+
+ if ($acct && $acct->RecordCount())
+ foreach ($acct->fields as $key=>$val)
+ if(!is_numeric($key) && empty($VAR[$key]))
+ $VAR[$key]=stripslashes($acct->fields[$key]);
+ }
+
+ $C_vars->strip_slashes_all();
+ $smarty->assign('VAR',$VAR);
+ $smarty->assign('plugin_template','checkout_plugin:plugin_ord_'.$rs->fields['checkout_plugin']);
}
- function add($VAR) {
- $this->checkout_construct();
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
+ public function tpl_get_plugindata($VAR) {
+ global $smarty;
- function view($VAR) {
- $this->checkout_construct();
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- function update($VAR) {
- $this->checkout_construct();
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- function delete($VAR) {
- $this->checkout_construct();
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- function search($VAR) {
- $this->checkout_construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- function search_show($VAR) {
- $this->checkout_construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
- function checkout_construct() {
- $this->module = "checkout";
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
+ # Normal checkout
+ $db = &DB();
+ $rs = $db->Execute(sqlSelect($db,'checkout','plugin_data',array('id'=>$VAR['checkout_id'])));
+ if ($rs || $rs->RecordCount() == 1)
+ $smarty->assign('plugin_data',$rs->fields['plugin_data']);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/checkout/checkout_construct.xml b/modules/checkout/checkout_construct.xml
index c43401b6..d7604e11 100644
--- a/modules/checkout/checkout_construct.xml
+++ b/modules/checkout/checkout_construct.xml
@@ -1,140 +1,178 @@
-
- checkout
-
-
-
-
-
- 0
-
- name
-
- 25
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- C(32)
- 1
- 32
- any
-
-
- C(255)
-
-
- L
-
-
- C(32)
- any
-
-
- X2
- array
- 1
-
-
- L
-
-
- L
-
-
- L
-
-
- F
-
-
- F
-
-
- I4
-
-
- L
-
-
- L
-
-
- X2
- array
- 1
-
-
- X2
- array
- 1
-
-
- F
-
-
- X2
- array
- 1
-
-
- X2
- array
- 1
-
-
- X2
- array
- 1
-
-
- X2
- array
- 1
-
-
- F
-
-
- X2
- array
- 1
- any
-
-
- X2
-
-
- X2
- array
- 1
-
-
- X2
- array
- 1
-
-
- C(128)
-
-
-
-
- id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,email_template,excluded_products,required_groups,graphic_url
- id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,email_template,excluded_products,required_groups,graphic_url
- id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,excluded_products,required_groups
- id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,email_template,excluded_products,required_groups,graphic_url
- id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,email_template,excluded_products,required_groups
-
-
- 0
+
+ checkout
+
+
+
+
+
+ 15
+
+ name
+
+ 25
+
+ 1
+
+
+
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ Active
+ L
+
+
+ C(32)
+ 1
+ 32
+ any
+
+
+ C(255)
+
+
+ C(32)
+ any
+
+
+ X2
+ array
+ 1
+
+
+ L
+
+
+ L
+
+
+ L
+
+
+ F
+
+
+ F
+
+
+ I4
+
+
+ L
+
+
+ L
+
+
+ X2
+ array
+ 1
+
+
+ X2
+ array
+ 1
+
+
+ F
+
+
+ X2
+ array
+ 1
+
+
+ X2
+ array
+ 1
+
+
+ X2
+ array
+ 1
+
+
+ X2
+ array
+ 1
+
+
+ F
+
+
+ X2
+ array
+ 1
+ any
+
+
+ X2
+
+
+ X2
+ array
+ 1
+
+
+ X2
+ array
+ 1
+
+
+ C(128)
+
+
+
+
+
+ id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,email_template,excluded_products,required_groups,graphic_url
+ id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,email_template,excluded_products,required_groups,graphic_url
+ id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,excluded_products,required_groups
+ id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,email_template,excluded_products,required_groups,graphic_url
+ id,site_id,name,description,active,checkout_plugin,plugin_data,allow_recurring,allow_new,allow_trial,total_minimum,total_maximum,max_decline_attempts,manual_approval_all,manual_approval_recur,manual_approval_country,manual_approval_group,manual_approval_amount,manual_approval_currency,default_when_currency,default_when_country,default_when_group,default_when_amount,allowed_currencies,email_template,excluded_products,required_groups
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ name
+
+
+ checkout_plugin
+
+
+ active
+ bool_icon
+ 20px
+
+
+
diff --git a/modules/checkout/checkout_install.xml b/modules/checkout/checkout_install.xml
index 124b080e..3daa48bb 100644
--- a/modules/checkout/checkout_install.xml
+++ b/modules/checkout/checkout_install.xml
@@ -1,45 +1,68 @@
+
+
- checkout
- setup
-
+
+
+
+ Checkout
+
1
+
+ checkout
+
+
+
+ setup
+
+
+
+
-
-
-
- search_form
-
-
- search
-
-
- view
-
- 1
-
-
- delete
-
-
- add
- 1
-
-
- update
-
-
- search_show
-
-
- admin_checkoutnow
-
-
- admin_adddiscount
-
-
- admin_preview
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+ admin_checkoutnow
+
+
+ admin_adddiscount
+
+
+ admin_preview
+
+
+
diff --git a/modules/core/auth.inc.php b/modules/core/auth.inc.php
index 8c3bab49..68bd2002 100644
--- a/modules/core/auth.inc.php
+++ b/modules/core/auth.inc.php
@@ -1,283 +1,304 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-class CORE_auth
-{
- var $auth_modules;
- var $auth_methods;
- var $account=false;
- var $logged=false;
- function CORE_auth($force)
- {
+/**
+ * The main AgileBill CORE Auth Class
+ *
+ * @package AgileBill
+ * @subpackage Core
+ */
+class CORE_auth {
+ private $account = 0;
+ private $logged = false;
+ private $group = array();
+
+ public function __construct($force) {
global $VAR;
- if(!isset( $this->auth_methods ) ) {
- #include (PATH_CORE . 'auth_methods.inc');
- #$this->auth_methods = $auth_methods;
- }
-
- if(defined("SESS_LOGGED")) {
- if(SESS_LOGGED == "1") {
- $this->logged = TRUE;
- $this->account = SESS_ACCOUNT;
+ if (defined('SESS_LOGGED')) {
+ if (SESS_LOGGED == '1') {
+ $this->logged = true;
+ $this->account = SESS_ACCOUNT;
}
- else {
- $this->logged = FALSE;
- $this->account = 0;
- }
- } else {
- $this->logged = FALSE;
- $this->account = 0;
- if(!defined('SESS_LOGGED')) define('SESS_LOGGED', false);
- if(!defined('SESS')) define('SESS', false);
+ } else {
+ if (! defined('SESS_LOGGED'))
+ define('SESS_LOGGED',false);
+ if (! defined('SESS'))
+ define('SESS',false);
}
- if($force && defined("FORCE_SESS_ACCOUNT")) {
+ if ($force && defined('FORCE_SESS_ACCOUNT')) {
$this->account = FORCE_SESS_ACCOUNT;
- $this->logged = TRUE;
- }
- $this->auth_update();
- if ( isset($VAR['_logout']) ||
- isset($VAR['_login']) ||
- isset($VAR['lid']) ||
- $force == true ||
- CACHE_SESSIONS != "1") {
- return;
- } else {
- if($this->session_auth_cache_retrieve())
- {
- $this->module_count = count($this->module);
- return;
- }
+ $this->logged = true;
+ }
+
+ $this->auth_update();
+
+ if (isset($VAR['_logout']) || isset($VAR['_login']) || isset($VAR['lid']) || $force == true || CACHE_SESSIONS != '1') {
+ return;
+
+ } else {
+ if ($this->session_auth_cache_retrieve()) {
+ $this->module_count = count($this->module);
+
+ return;
+ }
}
}
-
- function auth_update() {
- $this->group = array('0');
+ public function auth_update() {
+ $this->group = array('0');
$this->module = array('0');
-
- if($this->account) {
+
+ if ($this->account) {
$this->group_list($this->account);
- if (!$this->group) {
+
+ if (! $this->group)
return;
- }
- $db = &DB();
- $p = AGILE_DB_PREFIX;
- $sql="SELECT DISTINCT MM.module_id, GM.method_id, GM.group_id,
- M.name AS module_name, M.parent_id AS module_parent_id, M.menu_display AS module_display,
- MM.name AS method_name, MM.page AS method_page, MM.menu_display AS method_display
- FROM {$p}group_method as GM
- LEFT JOIN {$p}module as M on (GM.module_id=M.id and M.site_id=".DEFAULT_SITE.")
- LEFT JOIN {$p}module_method as MM on (GM.method_id=MM.id and MM.site_id=".DEFAULT_SITE.") ";
- for($i=0; $igroup); $i++)
- if($i==0) $sql .= "WHERE (GM.group_id={$this->group[$i]} ";
- else $sql .= "OR GM.group_id={$this->group[$i]} ";
- $sql .= ") AND GM.site_id=".DEFAULT_SITE." ORDER BY M.name,MM.name";
- $result=$db->Execute($sql);
- if($result === false)
- {
+
+ $db = &DB();
+ $p = AGILE_DB_PREFIX;
+ $sql = "
+SELECT DISTINCT MM.module_id, GM.method_id, GM.group_id, M.name AS module_name, M.parent_id AS module_parent_id, M.menu_display AS module_display, MM.name AS method_name, MM.page AS method_page, MM.menu_display AS method_display
+FROM {$p}group_method as GM
+LEFT JOIN {$p}module as M on (GM.module_id=M.id and M.site_id=".DEFAULT_SITE.")
+LEFT JOIN {$p}module_method as MM on (GM.method_id=MM.id and MM.site_id=".DEFAULT_SITE.") ";
+
+ for ($i=0; $igroup); $i++)
+ if ($i==0)
+ $sql .= sprintf('WHERE (GM.group_id=%s ',$this->group[$i]);
+ else
+ $sql .= sprintf('OR GM.group_id=%s ',$this->group[$i]);
+
+ $sql .= sprintf(') AND GM.site_id=%s ORDER BY M.name,MM.name',DEFAULT_SITE);
+ $result=$db->Execute($sql);
+
+ if ($result === false) {
global $C_debug;
- $C_debug->error('core:auth.inc.php','auth_update', $db->ErrorMsg() . ' ' .$q);
+
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg().' '.$q);
return;
}
+
while (!$result->EOF) {
- $module_name = $result->fields["module_name"];
- $method_name = $result->fields["method_name"];
+ $module_name = $result->fields['module_name'];
+ $method_name = $result->fields['method_name'];
- if(empty($this->module[$module_name])) {
- $this->module[$module_name] = array($result->fields["module_id"],
- $result->fields["module_parent_id"],
- $result->fields["module_display"]);
- }
+ if (empty($this->module[$module_name]))
+ $this->module[$module_name] = array($result->fields['module_id'],$result->fields['module_parent_id'],$result->fields['module_display']);
+
+ if (empty($this->module[$module_name][$method_name]))
+ $this->module[$module_name][$method_name] = array($result->fields['method_id'],$result->fields['method_display'],$result->fields['method_page']);
- if(empty($this->module[$module_name][$method_name])) {
- $this->module[$module_name][$method_name] = array($result->fields["method_id"],
- $result->fields["method_display"],
- $result->fields["method_page"]);
- }
$result->MoveNext();
}
}
+
$this->session_auth_cache_update();
}
-
- function session_auth_cache_update() {
+ private function session_auth_cache_update() {
$db = &DB();
- $expire = time() + 7200; // 1 hour
- if(isset($this->group) && gettype($this->group) == 'array')
- $group = serialize($this->group);
+ $expire = time()+7200; // 1 hour
+
+ if (isset($this->group) && is_array($this->group))
+ $group = serialize($this->group);
else
- $group = 0;
+ $group = 0;
- if(isset($this->module) && gettype($this->module) == 'array')
- $module = serialize($this->module);
+ if (isset($this->module) && is_array($this->module))
+ $module = serialize($this->module);
else
- $module = 0;
+ $module = 0;
- $q = 'DELETE FROM '.AGILE_DB_PREFIX.'session_auth_cache WHERE
- session_id = '. $db->qstr(SESS) .' AND
- site_id = '. $db->qstr(DEFAULT_SITE);
- $db->Execute($q);
-
- $id = $db->GenID(AGILE_DB_PREFIX . "" . 'session_auth_cache_id');
- $q = 'INSERT INTO '.AGILE_DB_PREFIX.'session_auth_cache SET
- id = '. $db->qstr($id) .',
- site_id = '. $db->qstr(DEFAULT_SITE) .',
- session_id = '. $db->qstr(SESS) .',
- date_expire = '. $db->qstr($expire) .',
- group_arr = '. $db->qstr($group) .',
- module_arr = '. $db->qstr($module);
- $db->Execute($q);
+ $db->Execute(sqlDelete($db,'session_auth_cache',array('session_id'=>SESS)));
+ $db->Execute(sqlInsert($db,'session_auth_cache',array('session_id'=>SESS,'date_expire'=>$expire,'group_arr'=>$group,'module_arr'=>$module)));
}
-
- function session_auth_cache_retrieve() {
+ private function session_auth_cache_retrieve() {
global $C_sess;
- if(!empty($C_sess->auth_cache)) {
- if ( $C_sess->auth_cache["date_expire"] > time() ) {
- $group = $C_sess->auth_cache['group_arr'];
- $module = $C_sess->auth_cache['module_arr'];
- if($group != '0' && $group != '') $this->group = unserialize($group);
- if($module != '0' && $module != '') $this->module = unserialize($module);
+
+ if (! empty($C_sess->auth_cache)) {
+ if ($C_sess->auth_cache['date_expire'] > time()) {
+ $group = $C_sess->auth_cache['group_arr'];
+ $module = $C_sess->auth_cache['module_arr'];
+
+ if ($group != '0' && $group != '')
+ $this->group = unserialize($group);
+ if ($module != '0' && $module != '')
+ $this->module = unserialize($module);
+
return true;
}
- }
+ }
$db = &DB();
- $q = 'SELECT * FROM '.AGILE_DB_PREFIX.'session_auth_cache WHERE
- site_id = '. $db->qstr(DEFAULT_SITE) .' AND
- session_id = '. $db->qstr(SESS) .' AND
- date_expire >= '. $db->qstr(time());
- $result = $db->Execute($q);
- if($result->RecordCount() > 0) {
- $group = $result->fields['group_arr'];
- $module = $result->fields['module_arr'];
- if($group != '0' && $group != '') $this->group = unserialize($group);
- if($module != '0' && $module != '') $this->module = unserialize($module);
+ $result = $db->Execute(sqlSelect($db,'session_auth_cache','*',sprintf('session_id=::%s:: AND date_expire >= %s',SESS,time())));
+ if ($result->RecordCount() > 0) {
+ $group = $result->fields['group_arr'];
+ $module = $result->fields['module_arr'];
+
+ if ($group != '0' && $group != '')
+ $this->group = unserialize($group);
+ if ($module != '0' && $module != '')
+ $this->module = unserialize($module);
+
return true;
}
+
return false;
}
-
- function group_list($account) {
- $this->group[0] = "0";
+ private function group_list($account) {
+ $this->group[0] = '0';
$time = time();
$db = &DB();
$p = AGILE_DB_PREFIX;
- $q="SELECT DISTINCT ag.group_id AS group_id,g.parent_id AS parent_id
- FROM {$p}account_group as ag
- INNER JOIN {$p}group as g ON (ag.group_id=g.id AND g.status=1 AND g.site_id=".DEFAULT_SITE.")
- WHERE ag.account_id = '$account'
- AND ( ag.date_start IS NULL OR ag.date_start < $time )
- AND ( ag.date_expire IS NULL OR ag.date_expire = 0 OR ag.date_expire > $time )
- AND ( g.date_start IS NULL OR g.date_start <= $time )
- AND ( g.date_expire IS NULL OR g.date_expire = 0 OR g.date_expire > $time )
- AND ag.active=1 AND g.status=1
- AND ag.site_id=".DEFAULT_SITE;
- $result = $db->Execute($q);
+ $q = "
+SELECT DISTINCT ag.group_id AS group_id,g.parent_id AS parent_id
+FROM {$p}account_group as ag
+INNER JOIN {$p}group as g ON (ag.group_id=g.id AND g.status=1 AND g.site_id=".DEFAULT_SITE.")
+WHERE ag.account_id = '$account'
+ AND (ag.date_start IS NULL OR ag.date_start < $time)
+ AND (ag.date_expire IS NULL OR ag.date_expire = 0 OR ag.date_expire > $time)
+ AND (g.date_start IS NULL OR g.date_start <= $time)
+ AND (g.date_expire IS NULL OR g.date_expire = 0 OR g.date_expire > $time)
+ AND ag.active=1 AND g.status=1
+ AND ag.site_id=".DEFAULT_SITE;
+
+ $result = $db->Execute($q);
+
if ($result === false) {
global $C_debug;
+
echo $db->ErrorMsg();
- $C_debug->error('auth.inc.php','group_list', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+
exit;
- } elseif($result->RecordCount() == 0) {
+
+ } elseif ($result->RecordCount() == 0) {
return;
- } else {
+
+ } else {
+ $arr = array();
while (!$result->EOF) {
- $arr[] = $result->fields;
+ array_push($arr,$result->fields);
$result->MoveNext();
}
}
- for($i=0; $igroup); $ii++)
- if($this->group[$ii] == $arr[$i]["group_id"]) $do = false;
- if($do) {
- $this->group[] = $arr[$i]["group_id"];
+ for ($ii=0; $iigroup); $ii++)
+ if ($this->group[$ii] == $arr[$i]['group_id'])
+ $do = false;
- if(!empty($arr[$i]["parent_id"]) && $arr[$i]["parent_id"] != $arr[$i]["group_id"]) {
+ if ($do) {
+ array_push($this->group,$arr[$i]['group_id']);
+
+ if (! empty($arr[$i]['parent_id']) && $arr[$i]['parent_id'] != $arr[$i]['group_id']) {
$do = true;
- for($ii=0; $iigroup); $ii++)
- if($this->group[$ii] == $arr[$i]["parent_id"]) $do = false;
- if($do) $this->group[] = $arr[$i]["parent_id"];
- }
+
+ for ($ii=0; $iigroup); $ii++)
+ if ($this->group[$ii] == $arr[$i]['parent_id'])
+ $do = false;
+
+ if ($do)
+ array_push($this->group,$arr[$i]['parent_id']);
+ }
}
}
- if($account != SESS_ACCOUNT) return $this->group;
- }
- function auth_method_by_name($module,$method) {
+ if ($account != SESS_ACCOUNT)
+ return $this->group;
+ }
- if(isset($this->module[$module][$method])) return TRUE;
+ public function auth_method_by_name($module,$method) {
+ if (isset($this->module[$module][$method]))
+ return true;
- if($module == 'core')
- if($method == 'cleanup')
+ if ($module == 'core')
+ if ($method == 'cleanup')
return true;
else
return false;
- if( is_file(PATH_MODULES.$module.'/auth.inc.php')) {
- include (PATH_MODULES.$module.'/auth.inc.php');
- $this->auth_methods = $auth_methods;
- for($i=0; $iauth_methods); $i++)
- if ($module == @$this->auth_methods[$i]['module'])
- if($method == false || $method == @$this->auth_methods[$i]['method'])
- return true;
- }
- return FALSE;
- }
+ if (is_file(PATH_MODULES.$module.'/auth.inc.php')) {
+ include(PATH_MODULES.$module.'/auth.inc.php');
+
+ $this->auth_methods = $auth_methods;
+
+ for ($i=0; $iauth_methods); $i++)
+ if ($module == @$this->auth_methods[$i]['module'])
+ if ($method == false || $method == @$this->auth_methods[$i]['method'])
+ return true;
+ }
- function auth_group_by_id($id) {
- if(!is_array($id))
- $ids[] = $id;
- else
- $ids = $id;
- foreach ( $ids as $group_id )
- if(isset($this->group))
- foreach ($this->group as $this_group_id)
- if($this_group_id == $group_id)
- return true;
return false;
}
- function auth_group_by_account_id($account, $id) {
- if(SESS_LOGGED == true && $account == SESS_ACCOUNT)
- return $this->auth_group_by_id($id);
- unset($this->group);
- $this->group_list($account);
- for($i=0; $i < count($this->group); $i++)
- if($this->group[$i] == $id) return true;
- return FALSE;
+ public function auth_group_by_id($id) {
+ $ids = array();
+
+ if (! is_array($id))
+ array_push($ids,$id);
+ else
+ $ids = $id;
+
+ foreach ($ids as $group_id)
+ if (isset($this->group))
+ foreach ($this->group as $this_group_id)
+ if ($this_group_id == $group_id)
+ return true;
+
+ return false;
}
- function generate_admin_menu() {
+ public function auth_group_by_account_id($account, $id) {
+ if (SESS_LOGGED == true && $account == SESS_ACCOUNT)
+ return $this->auth_group_by_id($id);
+
+ unset($this->group);
+ $this->group_list($account);
+
+ for ($i=0; $igroup); $i++)
+ if ($this->group[$i] == $id)
+ return true;
+
+ return false;
+ }
+
+ /**
+ * Generate the admin menu
+ */
+ public function generate_admin_menu() {
include_once(PATH_CORE.'auth_generate_admin_menu.inc.php');
+
return auth_generate_admin_menu($this);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/auth_generate_admin_menu.inc.php b/modules/core/auth_generate_admin_menu.inc.php
index fcd26686..c620254e 100644
--- a/modules/core/auth_generate_admin_menu.inc.php
+++ b/modules/core/auth_generate_admin_menu.inc.php
@@ -1,149 +1,150 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Menu
*/
-
-// generate the admin menu
-function auth_generate_admin_menu($menu_obj)
-{
- $menu_obj->auth_update();
- global $C_translate, $smarty, $C_list;
- $i=1;
- $js='';
- $arr = $menu_obj->module;
+/**
+ * The main AgileBill Admin Menu Method
+ *
+ * @package AgileBill
+ * @subpackage Menu
+ */
+
+function auth_generate_admin_menu($menu_obj) {
+ global $C_translate,$smarty,$C_list;
+
+ $menu_obj->auth_update();
+
+ $i = 1;
+ $js = '';
+ $arr = $menu_obj->module;
$arr2 = $menu_obj->module;
- // loop through the modules
- while (list($module, $val) = each ($arr)) {
- if(!empty($val[2])) {
- if($val[1] == $val[0] || empty($val[0]) || empty($val[1]))
- {
- $module_name = $C_translate->translate('menu',$module,'');
+ # Loop through the modules
+ while (list($module,$val) = each($arr)) {
+ if (! empty($val[2])) {
+ if ($val[1] == $val[0] || empty($val[0]) || empty($val[1])) {
+ $module_name = $C_translate->translate('menu',$module,'','menutitle');
$parent = $val[0];
$module_id = $val[0];
- $module_arr[$i]["name"] = $module_name;
- $module_arr[$i]["module"] = $module;
+ $module_arr[$i]['name'] = $module_name;
+ $module_arr[$i]['module'] = $module;
+
+ # Loop through the methods
+ while (list($method,$meth_arr) = each($arr[$module])) {
+ if (gettype($meth_arr) == 'array' && ! empty($meth_arr[1])) {
+ $method_name = $C_translate->translate($method,$module,'','methodtitle');
- // loop through the methods
- while (list($method, $meth_arr) = each ($arr[$module])) {
- if(gettype($meth_arr) == 'array' && !empty($meth_arr[1])) {
- $method_name = $C_translate->translate('menu_'.$method,$module,'');
if(empty($meth_arr[2]))
$page = $module.':'.$method;
else
- $page = preg_replace('/%%/', $module, $meth_arr[2]);
-
- $module_arr[$i]["methods"][] = Array('name' => $method_name, 'page' => $page);
+ $page = htmlspecialchars(str_replace('%%',$module,$meth_arr[2]));
+ $module_arr[$i]['methods'][] = array('name'=>$method_name,'page'=>$page);
}
}
- // Loop through the sub-modules:
+ # Loop through the sub-modules:
reset($arr2);
- $ii=0;
- while (list($module, $val) = each ($arr2)) {
- if(!empty($val[2])) {
- if($val[1] == $parent && $module_id != $val[0])
- {
- $module_name = $C_translate->translate('menu',$module,'');
- $module_arr[$i]["sub_name"][$ii] = $module_name;
+ $ii = 0;
+ while (list($module,$val) = each ($arr2)) {
+ if (! empty($val[2])) {
+ if ($val[1] == $parent && $module_id != $val[0]) {
+ $module_name = $C_translate->translate('menu',$module,'','menutitle');
+ $module_arr[$i]["sub_name"][$ii] = $module_name;
- // loop through the methods
- while (list($method, $meth_arr) = each ($arr2[$module])) {
- if(gettype($meth_arr) == 'array' && !empty($meth_arr[1])) {
- $method_name = $C_translate->translate('menu_'.$method,$module,'');
- if(empty($meth_arr[2]))
- $page = $module.':'.$method;
- else
- $page = preg_replace('/%%/', $module, $meth_arr[2]);
- $module_arr[$i]["sub_methods"][$ii][] = Array('name' => $method_name, 'page' => $page);
- }
+ # Loop through the methods
+ while (list($method,$meth_arr) = each($arr2[$module])) {
+ if (gettype($meth_arr) == 'array' && ! empty($meth_arr[1])) {
+ $method_name = $C_translate->translate($method,$module,'','methodtitle');
+
+ if(empty($meth_arr[2]))
+ $page = $module.':'.$method;
+ else
+ $page = htmlspecialchars(str_replace('%%',$module,$meth_arr[2]));
+
+ $module_arr[$i]['sub_methods'][$ii][] = array('name'=>$method_name,'page'=>$page);
}
- $ii++;
}
+
+ $ii++;
}
}
- $i++;
+ }
- }
- }
+ $i++;
+ }
+ }
}
-
-
-
- // Generate the main modules:
+ # Generate the main modules:
$js = '';
$js .= ".|Overview|javascript:openUrl('?_page=core:admin');\n";
$js .= ".|Exit Administration|javascript:exitAdmin();\n";
- $js .= ".|Misc\n";
- $js .= "..|Documentation|http://agilebill.com/documentation|||mainFrame\n";
- $js .= "..|Agileco News|http://forum.agileco.com/forumdisplay.php?f=26|||mainFrame\n";
- $js .= "..|Version Check|?_page=module:upgrade|||mainFrame\n";
- for($i=1; $i<=count($module_arr); $i++)
- {
+ for ($i=1; $i<=count($module_arr); $i++) {
$name = $module_arr[$i]['name'];
$js .= ".|{$name}\n";
- // Generate the main methods:
- for($ii=0; $iiassign('today_start', $C_list->date(mktime(0,0,0,date("m"),date("d"), date("Y"))));
- $smarty->assign('week_start', $C_list->date(mktime(0,0,0,date("m"),date("d")-7, date("Y"))));
- $smarty->assign('month_start', $C_list->date(mktime(0,0,0,date("m"),1, date("Y"))));
+ # Set the dates for the quicksearch
+ $smarty->assign('today_start',$C_list->date(mktime(0,0,0,date('m'),date('d'),date('Y'))));
+ $smarty->assign('week_start',$C_list->date(mktime(0,0,0,date('m'),date('d')-7,date('Y'))));
+ $smarty->assign('month_start',$C_list->date(mktime(0,0,0,date('m'),1,date('Y'))));
# Generate the menu
- require_once(PATH_INCLUDES."phplayers/PHPLIB.php");
- require_once(PATH_INCLUDES."phplayers/layersmenu-common.inc.php");
- require_once(PATH_INCLUDES."phplayers/treemenu.inc.php");
+ require_once(PATH_INCLUDES.'phplayers/PHPLIB.php');
+ require_once(PATH_INCLUDES.'phplayers/layersmenu-common.inc.php');
+ require_once(PATH_INCLUDES.'phplayers/treemenu.inc.php');
- // unstoppable agileco logo ;)
- echo ' ';
+ # Unstoppable agileco logo ;)
+ echo ' ';
$mnu = new TreeMenu();
$mnu->setMenuStructureString($js);
- $mnu->setIconsize(16, 16);
+ $mnu->setIconsize(16,16);
$mnu->parseStructureForMenu('treemenu1');
- $mnu->setTreemenuTheme("kde_");
- return $mnu->newTreeMenu('treemenu1');
- return $js;
-
+ $mnu->setTreemenuTheme('kde_');
+ return $mnu->newTreeMenu('treemenu1');
}
?>
diff --git a/modules/core/crypt.inc.php b/modules/core/crypt.inc.php
index 95cef43f..a16826a9 100644
--- a/modules/core/crypt.inc.php
+++ b/modules/core/crypt.inc.php
@@ -1,77 +1,119 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
+ *
+ * @link http://www.agileco.com/
+ * @copyright 2004-2008 Agileco, LLC.
+ * @license http://www.agileco.com/agilebill/license1-4.txt
+ * @author Tony Landis
+ * @package AgileBill
+ * @subpackage Core
+ */
- var $primes;
- var $maxprimes;
+if (! defined('LICENSE_KEY'))
+ define('LICENSE_KEY','47012093-4943-32127707');
- function SecurityRSA($show_debug=0) {
- mt_srand((double)microtime()*1000000);
- $this->primes = array (4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597,
- 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751,
- 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931,
- 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051,
- 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227,
- 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399,
- 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521,
- 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683,
- 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839,
- 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007,
- 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151,
- 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301,
- 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451,
- 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637,
- 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791,
- 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949,
- 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103,
- 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253,
- 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477,
- 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589,
- 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741,
- 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919,
- 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093,
- 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263,
- 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429,
- 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609,
- 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741,
- 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893,
- 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059,
- 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227,
- 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397,
- 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533);
- $this->maxprimes = count($this->primes) - 1;
+/**
+ * The main AgileBill CORE RSA Class
+ *
+ * @package AgileBill
+ * @subpackage Core
+ * @todo This Class appears unused.
+ */
+class CORE_RSA {
+ private $primes = array();
+ private $maxprimes = 0;
+
+ public function __construct() {
+ mt_srand((double)microtime()*1000000);
+
+ $this->primes = array(
+ 4507,4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,
+ 4603,4621,4637,4639,4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,
+ 4759,4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,4919,4931,
+ 4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999,5003,5009,5011,5021,5023,5039,5051,
+ 5059,5077,5081,5087,5099,5101,5107,5113,5119,5147,5153,5167,5171,5179,5189,5197,5209,5227,
+ 5231,5233,5237,5261,5273,5279,5281,5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,
+ 5407,5413,5417,5419,5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,
+ 5527,5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,5669,5683,
+ 5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,5807,5813,5821,5827,5839,
+ 5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,5903,5923,5927,5939,5953,5981,5987,6007,
+ 6011,6029,6037,6043,6047,6053,6067,6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,
+ 6163,6173,6197,6199,6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,
+ 6311,6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,6449,6451,
+ 6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,6581,6599,6607,6619,6637,
+ 6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,6719,6733,6737,6761,6763,6779,6781,6791,
+ 6793,6803,6823,6827,6829,6833,6841,6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,
+ 6959,6961,6967,6971,6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,
+ 7109,7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,7247,7253,
+ 7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,7433,7451,7457,7459,7477,
+ 7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,7547,7549,7559,7561,7573,7577,7583,7589,
+ 7591,7603,7607,7621,7639,7643,7649,7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,
+ 7753,7757,7759,7789,7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919,
+ 7927,7933,7937,7949,7951,7963,7993,8009,8011,8017,8039,8053,8059,8069,8081,8087,8089,8093,
+ 8101,8111,8117,8123,8147,8161,8167,8171,8179,8191,8209,8219,8221,8231,8233,8237,8243,8263,
+ 8269,8273,8287,8291,8293,8297,8311,8317,8329,8353,8363,8369,8377,8387,8389,8419,8423,8429,
+ 8431,8443,8447,8461,8467,8501,8513,8521,8527,8537,8539,8543,8563,8573,8581,8597,8599,8609,
+ 8623,8627,8629,8641,8647,8663,8669,8677,8681,8689,8693,8699,8707,8713,8719,8731,8737,8741,
+ 8747,8753,8761,8779,8783,8803,8807,8819,8821,8831,8837,8839,8849,8861,8863,8867,8887,8893,
+ 8923,8929,8933,8941,8951,8963,8969,8971,8999,9001,9007,9011,9013,9029,9041,9043,9049,9059,
+ 9067,9091,9103,9109,9127,9133,9137,9151,9157,9161,9173,9181,9187,9199,9203,9209,9221,9227,
+ 9239,9241,9257,9277,9281,9283,9293,9311,9319,9323,9337,9341,9343,9349,9371,9377,9391,9397,
+ 9403,9413,9419,9421,9431,9433,9437,9439,9461,9463,9467,9473,9479,9491,9497,9511,9521,9533);
+
+ $this->maxprimes = count($this->primes)-1;
}
- function generate_keys($show_debug=0){
- while (empty($e) || empty($d)) {
- $p = $this->primes[mt_rand(0, $this->maxprimes)];
- while (empty($q) || ($p==$q)) {
- $q = $this->primes[mt_rand(0, $this->maxprimes)];
- }
- $n = $p*$q;
- $pi = ($p - 1) * ($q - 1);
- $e = $this->tofindE($pi, $p, $q);
- $d = $this->extend($e,$pi);
- $keys = array ($n, $e, $d);
+ public function generate_keys(){
+ $e = false;
+ $d = false;
+ $q = false;
+
+ while (! $e || ! $d) {
+ $p = $this->primes[mt_rand(0,$this->maxprimes)];
+
+ while (! $q || ($p==$q))
+ $q = $this->primes[mt_rand(0,$this->maxprimes)];
+
+ $n = $p*$q;
+ $pi = ($p-1)*($q-1);
+ $e = $this->tofindE($pi,$p,$q);
+ $d = $this->extend($e,$pi);
+ $keys = array($n,$e,$d);
}
+
return $keys;
- }
- function mo($g, $l) {
- return $g - ($l * floor ($g/$l));
}
- function extend($Ee,$Epi) {
+ private function mo($g,$l) {
+ return $g-($l*floor($g/$l));
+ }
+
+ private function extend($Ee,$Epi) {
$u1 = 1;
$u2 = 0;
$u3 = $Epi;
$v1 = 0;
$v2 = 1;
$v3 = $Ee;
+
while ($v3 != 0) {
$qq = floor($u3/$v3);
- $t1 = $u1 - $qq * $v1;
- $t2 = $u2 - $qq * $v2;
- $t3 = $u3 - $qq * $v3;
+ $t1 = $u1-$qq*$v1;
+ $t2 = $u2-$qq*$v2;
+ $t3 = $u3-$qq*$v3;
$u1 = $v1;
$u2 = $v2;
$u3 = $v3;
@@ -80,172 +122,212 @@ class CORE_RSA
$v3 = $t3;
$z = 1;
}
+
$uu = $u1;
$vv = $u2;
- if ($vv < 0) {
- $inverse = $vv + $Epi;
- } else {
+
+ if ($vv < 0)
+ $inverse = $vv+$Epi;
+ else
$inverse = $vv;
- }
+
return $inverse;
}
- function GCD($e,$pi) {
+ private function GCD($e,$pi) {
$y = $e;
$x = $pi;
+
while ($y != 0) {
- $w = $this->mo($x , $y);
+ $w = $this->mo($x,$y);
$x = $y;
$y = $w;
}
+
return $x;
}
- function tofindE($pi) {
+ private function tofindE($pi) {
$great = 0;
- $cc = mt_rand (0,$this->maxprimes);
+ $cc = mt_rand(0,$this->maxprimes);
$startcc = $cc;
+
while ($cc >= 0) {
$se = $this->primes[$cc];
$great = $this->GCD($se,$pi);
$cc--;
- if ($great == 1) break;
+
+ if ($great == 1)
+ break;
}
+
if ($great == 0) {
$cc = $startcc + 1;
+
while ($cc <= $this->maxprimes) {
$se = $this->primes[$cc];
$great = $this->GCD($se,$pi);
$cc++;
- if ($great == 1) break;
+
+ if ($great == 1)
+ break;
}
}
+
return $se;
}
- function rsa_encrypt($m, $e, $n) {
- $asci = array ();
+ public function rsa_encrypt($m,$e,$n) {
+ $asci = array();
+ $coded = '';
+
for ($i=0; $ipowmod($asci[$k], $e, $n);
- @$coded .= $resultmod." ";
+ for ($k=0; $k< count($asci); $k++) {
+ $resultmod = $this->powmod($asci[$k],$e,$n);
+ $coded .= $resultmod.' ';
}
- return trim(@$coded);
+
+ return trim($coded);
}
- function powmod($base, $exp, $modulus) {
+ private function powmod($base,$exp,$modulus) {
$accum = 1;
$i = 0;
$basepow2 = $base;
+
while (($exp >> $i)>0) {
- if ((($exp >> $i) & 1) == 1) {
- $accum = $this->mo(($accum * $basepow2) , $modulus);
- }
- $basepow2 = $this->mo(($basepow2 * $basepow2) , $modulus);
+ if ((($exp >> $i) & 1) == 1)
+ $accum = $this->mo(($accum*$basepow2),$modulus);
+
+ $basepow2 = $this->mo(($basepow2*$basepow2),$modulus);
+
$i++;
}
+
return $accum;
}
- function rsa_decrypt($c, $d, $n) {
- $decryptarray = explode(" ", $c);
- for ($u=0; $upowmod($decryptarray[$u], $d, $n);
- @$deencrypt.= substr ($resultmod,1,strlen($resultmod)-2);
- }
- for ($u=0; $upowmod($decryptarray[$u],$d,$n);
+ $deencrypt .= substr($resultmod,1,strlen($resultmod)-2);
}
- return @$resultd;
+
+ for ($u=0; $ursa_encrypt($data,$keys[1],$keys[0]);
+ $rc4_data = do_rc4($rsa_data,'en',$rc4_key);
-function CORE_encrypt($data) {
- if(LICENSE_KEY == '') return $data; // provide a license key in the setup area to enable encryption
- $rsa = new CORE_RSA;
- $keys = explode('-', LICENSE_KEY);
- $rsa_data = $rsa->rsa_encrypt($data, $keys[1], $keys[0]);
- $rc4_key = do_rc4(LICENSE_KEY, 'en', false);
- $rc4_data = do_rc4($rsa_data, 'en', $rc4_key);
return $rc4_data;
}
+/**
+ * Decrypt the data
+ */
+function CORE_decrypt($data) {
+ $rsa = new CORE_RSA;
+
+ $keys = explode('-',LICENSE_KEY);
+ $rc4_key = do_rc4(LICENSE_KEY,'en',false);
+
+ $rc4_data = do_rc4($data,'de',$rc4_key);
+ $rsa_data = $rsa->rsa_decrypt($rc4_data,$keys[2],$keys[0]);
-function CORE_decrypt($data) {
- if(LICENSE_KEY == '') return $data; // provide a license key in the setup area to enable encryption
- $rc4_key = do_rc4(LICENSE_KEY, 'en', false);
- $rc4_data = do_rc4($data, 'de', $rc4_key);
- $rsa = new CORE_RSA;
- $keys = explode('-', LICENSE_KEY);
- $rsa_data = $rsa->rsa_decrypt($rc4_data, $keys[2], $keys[0]);
return $rsa_data;
}
+/**
+ * Do the encryption/decryption
+ */
+function do_rc4($data,$case,$pwd) {
+ if (! $pwd)
+ $pwd = '21e0*kO-(uV9B0@jFk-er';
-function do_rc4($data, $case, $pwd) {
- if(!$pwd) $pwd = '21e0*kO-(uV9B0@jFk-er';
- if ($case == 'de') {
+ if ($case == 'de')
$data = urldecode($data);
- }
- $key[] = "";
- $box[] = "";
- $temp_swap = "";
- $pwd_length = 0;
- $pwd_length = strlen($pwd);
+
+ $key = array();
+ $box = array();
+ $temp_swap = '';
+ $pwd_length = strlen($pwd);
+
for ($i = 0; $i <= 255; $i++) {
- $key[$i] = ord(substr($pwd, ($i % $pwd_length), 1));
+ $key[$i] = ord(substr($pwd,($i%$pwd_length),1));
$box[$i] = $i;
}
- $x = 0;
- for ($i = 0; $i <= 255; $i++) {
- $x = ($x + $box[$i] + $key[$i]) % 256;
+
+ $x = 0;
+ for ($i=0; $i<=255; $i++) {
+ $x = ($x+$box[$i]+$key[$i])%256;
$temp_swap = $box[$i];
$box[$i] = $box[$x];
$box[$x] = $temp_swap;
}
- $temp = "";
- $k = "";
- $cipherby = "";
- $cipher = "";
+
+ $temp = '';
+ $k = '';
+ $cipherby = '';
+ $cipher = '';
$a = 0;
$j = 0;
- for ($i = 0; $i < strlen($data); $i++) {
- $a = ($a + 1) % 256;
- $j = ($j + $box[$a]) % 256;
+
+ for ($i=0; $i
\ No newline at end of file
+}
+?>
diff --git a/modules/core/database.inc.php b/modules/core/database.inc.php
index 502665ff..fd7eec23 100644
--- a/modules/core/database.inc.php
+++ b/modules/core/database.inc.php
@@ -1,262 +1,363 @@
-
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-class CORE_database
-{
- function add($VAR, &$construct, $type)
- {
- include_once(PATH_CORE . 'database_add.inc.php');
- return CORE_database_add($VAR, $construct, $type);
+
+/**
+ * The main AgileBill CORE Database Class
+ *
+ * @package AgileBill
+ * @subpackage Core
+ */
+class CORE_database {
+ public function add($VAR,$construct,$type) {
+ include_once(PATH_CORE.'database_add.inc.php');
+ return CORE_database_add($VAR,$construct,$type);
}
- function update($VAR, &$construct, $type)
- {
- include_once(PATH_CORE . 'database_update.inc.php');
- return CORE_database_update($VAR, $construct, $type);
+ public function update($VAR,$construct,$type) {
+ include_once(PATH_CORE.'database_update.inc.php');
+ return CORE_database_update($VAR,$construct,$type);
}
- function search_form($VAR, &$construct, $type)
- {
- include_once(PATH_CORE . 'database_search_form.inc.php');
- return CORE_database_search_form($VAR, $construct, $type);
+ public function search_form($VAR,$construct,$type) {
+ include_once(PATH_CORE.'database_search_form.inc.php');
+ return CORE_database_search_form($VAR,$construct,$type);
}
- function search($VAR, &$construct, $type)
- {
- include_once(PATH_CORE . 'database_search.inc.php');
- return CORE_database_search($VAR, $construct, $type);
+ public function search($VAR,$construct,$type) {
+ include_once(PATH_CORE.'database_search.inc.php');
+ return CORE_database_search($VAR,$construct,$type);
}
- function search_show($VAR, &$construct, $type)
- {
- include_once(PATH_CORE . 'database_search_show.inc.php');
- return CORE_database_search_show($VAR, $construct, $type);
- }
-
- function view($VAR, &$construct, $type)
- {
- include_once(PATH_CORE . 'database_view.inc.php');
- return CORE_database_view($VAR, $construct, $type);
- }
-
- function mass_delete($VAR, &$construct, $type)
- {
- include_once(PATH_CORE . 'database_mass_delete.inc.php');
- return CORE_database_mass_delete($VAR, $construct, $type);
- }
-
- function delete($VAR, &$construct, $type)
- {
- include_once(PATH_CORE . 'database_delete.inc.php');
- return CORE_database_delete($VAR, $construct, $type);
+ public function search_show($VAR,$construct,$type) {
+ include_once(PATH_CORE.'database_search_show.inc.php');
+ return CORE_database_search_show($VAR,$construct,$type);
}
- function join_fields($result, $linked)
- {
- include_once(PATH_CORE . 'database_join_fields.inc.php');
- return CORE_database_join_fields($result, $linked);
- }
+ public function view($VAR,$construct,$type) {
+ include_once(PATH_CORE.'database_view.inc.php');
+ return CORE_database_view($VAR,$construct,$type);
+ }
+
+ public function mass_delete($VAR,$construct,$type) {
+ include_once(PATH_CORE.'database_mass_delete.inc.php');
+ return CORE_database_mass_delete($VAR,$construct,$type);
+ }
+
+ public function delete($VAR,$construct,$type) {
+ include_once(PATH_CORE.'database_delete.inc.php');
+ return CORE_database_delete($VAR,$construct,$type);
+ }
+
+ public function join_fields($result,$linked) {
+ include_once(PATH_CORE.'database_join_fields.inc.php');
+ return CORE_database_join_fields($result,$linked);
+ }
// replaced in v1.4.91 (use sqlSelect)
- function sql_select($TableList, $FieldList, $Conditions, $Order, &$db) {
- return sqlSelect( $db, $TableList, $FieldList, $Conditions, $Order);
+ # @todo To deprecate
+ public function sql_select($TableList,$FieldList,$Conditions,$Order,&$db) {
+ return sqlSelect($db,$TableList,$FieldList,$Conditions,$Order);
}
/**
- * Remove fields from the standard construct type to ingore insert/select/validation rules set in construct
+ * Remove fields from the standard construct type to ignore insert/select/validation rules set in construct
*
* @param array $ignore_fields
* @param string $construct_fields
* @return array
*/
- function ignore_fields($ignore_fields,$construct_fields) {
- if(!is_array($construct_fields)) $fields = explode(",", $construct_fields); else $fields = $construct_fields;
- foreach($fields as $id=>$fld) {
- if(in_array($fld,$ignore_fields)) {
+ public function ignore_fields($ignore_fields,$construct_fields) {
+ if (! is_array($construct_fields))
+ $fields = explode(',',$construct_fields);
+ else
+ $fields = $construct_fields;
+
+ foreach ($fields as $id=>$fld)
+ if (in_array($fld,$ignore_fields))
unset($fields[$id]);
- }
- }
- return $fields;
+
+ return $fields;
}
}
-
-class CORE_debugger
-{
- var $sql_count;
-
- function sql_count() {
- if(!isset($this->sql_count)) $this->sql_count = 0;
- $this->sql_count++;
+/**
+ * The main AgileBill CORE Debugger Class
+ *
+ * @package AgileBill
+ * @subpackage Core
+ */
+class CORE_debugger {
+ public function alert($message) {
+ $this->alert = array($message);
}
- function alert($message) {
- $this->alert = Array ($message);
- }
+ public function error($module,$method,$message) {
+ $this->error = sprintf('%s:%s => %s ',$module,$method,$message);
+
+ if (defined('ERROR_REPORTING') && ERROR_REPORTING > 0)
+ $this->alert($this->error);
- function error($module, $method, $message) {
- $this->error = $module . ':'. $method . ' =>   ' . $message . ' ';
- if(defined("ERROR_REPORTING") && ERROR_REPORTING > 0) $this->alert($this->error);
$db = &DB();
- $this->record_id = $db->GenID(AGILE_DB_PREFIX . "" . 'log_error_id');
- $q = "INSERT INTO ".AGILE_DB_PREFIX."log_error
- SET
- id = ". $db->qstr($this->record_id).",
- date_orig = ". $db->qstr(time()).",
- account_id = ". @$db->qstr(SESS_ACCOUNT).",
- module = ". $db->qstr($module).",
- method = ". $db->qstr($method).",
- message = ". $db->qstr($message).",
- site_id = ". @$db->qstr(DEFAULT_SITE);
- $result = $db->Execute($q);
+ $result = $db->Execute(sqlInsert($db,'log_error',array('date_orig'=>time(),'account_id'=>SESS_ACCOUNT,'module'=>$module,'method'=>$method,'message'=>$message)));
}
-}
+}
-
-function &DB($debug=false) {
+/**
+ * The main AgileBill CORE Database Function
+ */
+function DB($debug=false) {
static $saved_db_conn;
- if (isset($saved_db_conn) && defined("AGILE_DB_CACHE")) {
- #echo 'Cached: '.print_r($saved_db_conn,true).' ';
- if($debug) $saved_db_conn->debug=true; else $saved_db_conn->debug=false;
+ if (isset($saved_db_conn) && defined('AGILE_DB_CACHE')) {
+ if ($debug)
+ $saved_db_conn->debug = true;
+ else
+ $saved_db_conn->debug = false;
+
return $saved_db_conn;
}
$saved_db_conn = NewADOConnection(AGILE_DB_TYPE);
- if(defined("AGILE_DB_PCONNECT") && AGILE_DB_PCONNECT == true)
+ if (defined('AGILE_DB_PCONNECT') && AGILE_DB_PCONNECT == true)
$saved_db_conn->PConnect(AGILE_DB_HOST,AGILE_DB_USERNAME,AGILE_DB_PASSWORD,AGILE_DB_DATABASE);
else
$saved_db_conn->Connect(AGILE_DB_HOST,AGILE_DB_USERNAME,AGILE_DB_PASSWORD,AGILE_DB_DATABASE);
- #echo 'Original: '.print_r($saved_db_conn,true).' ';
- if($debug) $saved_db_conn->debug=true; else $saved_db_conn->debug=false;
- return $saved_db_conn;
-}
+ if ($debug)
+ $saved_db_conn->debug = true;
+ else
+ $saved_db_conn->debug = false;
-function sqlGenID(&$db, $table) {
- return $db->GenID( AGILE_DB_PREFIX . $table . '_id' );
+ $saved_db_conn->SetFetchMode(ADODB_FETCH_ASSOC);
+
+ return $saved_db_conn;
}
-function sqlConditions( &$db, $Conditions=false, $Tables=false )
-{
- $where = " WHERE ";
+/**
+ * Get the next SQL index ID for a table
+ *
+ * @param $db
+ * @param $table
+ * @return int
+ */
+function sqlGenID($db,$table) {
+ $id = 0;
- if($Conditions) {
- if(preg_match('/::/', $Conditions) ) {
- $s = explode('::', $Conditions);
- $ii=1;
- $Conditions = '';
- for($i=0; $iqstr($s[$i]);
- $ii=1;
- }
- }
+ # Check if our ID table exists, and if not
+ static $CACHE = array();
+ $dbname = md5($db->databaseType.$db->host.$db->database.$db->user);
+
+ if (! isset($CACHE[$dbname][$table])) {
+ $CACHE[$dbname][$table] = true;
+ $rs = $db->Execute(sprintf('SELECT id FROM %s%s_id WHERE 1=0',AGILE_DB_PREFIX,$table));
+
+ if ($rs) {
+ $rs = $db->Execute(sprintf('SELECT MAX(id) AS max FROM %s%s',AGILE_DB_PREFIX,$table));
+ if ($rs)
+ $id = $rs->fields['max']+1;
}
- $where .= $Conditions . " AND ";
}
- if(!is_array($Tables)) {
- $where .= " site_id = ". DEFAULT_SITE;
- } else {
- $tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V');
- for($i=0; $i 0 ) $where .= " AND ";
- $where .= " {$tbarr[$i]}.site_id = ". DEFAULT_SITE;
- }
- }
-
- if( $where ) return $where;
+ return $db->GenID(sprintf('%s%s_id',AGILE_DB_PREFIX,$table),$id);
}
-function sqlDelete(&$db, $table, $conditions) {
- $conditions = sqlConditions( $db, $conditions);
- return "DELETE FROM ".AGILE_DB_PREFIX."$table $conditions";
-}
+/**
+ * Generate SQL Conditions for a Query
+ */
+function sqlConditions($db,$Conditions=false,$Tables=false) {
+ $db = &DB();
+ $where = 'WHERE ';
-function sqlInsert(&$db, $table, $fields, $id=false) {
- if(!$id) $id = sqlGenID( $db,$table);
- $fields['id'] = $id;
- if(empty($fields['site_id'])) $fields['site_id'] = DEFAULT_SITE;
- $tab = AGILE_DB_PREFIX.''.$table;
- return $db->GetInsertSQL($tab, $fields, get_magic_quotes_gpc());
-}
+ if ($Conditions) {
+ if (is_array($Conditions)) {
+ foreach ($Conditions as $a => $b)
+ if (is_array($b))
+ $where .= sprintf("%s IN ('%s') AND ",$a,implode("','",$b));
+ elseif ($db->qstr($b) == 'NULL')
+ $where .= sprintf('%s IS NULL AND ',$a);
+ else
+ $where .= sprintf('%s=%s AND ',$a,$db->qstr($b));
-function sqlUpdate(&$db, $table, $fields, $conditions, $force=false) {
- $rs = $db->Execute( sqlSelect( $db, $table, '*', $conditions) );
- if(empty($fields['site_id'])) $fields['site_id'] = DEFAULT_SITE;
- return $db->GetUpdateSQL( $rs, $fields, false, get_magic_quotes_gpc());
-}
+ } else {
+ if (preg_match('/::/',$Conditions)) {
+ $s = explode('::',$Conditions);
+ $ii = 1;
+ $Conditions = '';
-function sqlSelect(&$db, $TableList, $FieldList, $Conditions, $Order=false, $Limit=false, $DISTINCT='', $GroupBy=false )
-{
- ### Table(s)
- if(is_array($TableList)) {
- $tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S', 'T','U','V');
- $table = '';
- $site_id_where = '';
- for($i=0;$i0) {
- $table .= ",".AGILE_DB_PREFIX.$TableList[$i] . " AS $as";
- } else {
- $table .= AGILE_DB_PREFIX.$TableList[$i] . " AS $as";
+ for ($i=0; $iqstr($s[$i]);
+ $ii = 1;
+ }
+ }
}
+
+ $where .= sprintf('%s AND ',$Conditions);
+ }
+ }
+
+ # Add the SITE ID
+ if (! is_array($Tables) || count($Tables) == 1) {
+ $where .= sprintf('site_id=%s',DEFAULT_SITE);
+
+ } else {
+ $tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V');
+ for ($i=0; $i0)
+ $where .= ' AND ';
+
+ $where .= sprintf(' %s.site_id = %s',$tbarr[$i],DEFAULT_SITE);
+ }
+ }
+
+ $where = str_replace('{p}',AGILE_DB_PREFIX,$where);
+
+ return $where;
+}
+
+/**
+ * Generate SQL to delete from the database
+ */
+function sqlDelete($db,$table,$where) {
+ $db = &DB();
+ $where = sqlConditions($db,$where);
+
+ return sprintf('DELETE FROM %s%s %s',AGILE_DB_PREFIX,$table,$where);
+}
+
+/**
+ * Generate SQL to insert into the database
+ */
+function sqlInsert($db,$table,$FieldList,$id=false) {
+ $db = &DB();
+
+ if (! $id)
+ $id = sqlGenID($db,$table);
+
+ $FieldList['id'] = $id;
+ if (empty($FieldList['site_id']))
+ $FieldList['site_id'] = DEFAULT_SITE;
+
+ $table = AGILE_DB_PREFIX.$table;
+ return $db->GetInsertSQL($table,$FieldList,get_magic_quotes_gpc());
+}
+
+/**
+ * Generate SQL to update records in the database
+ */
+function sqlUpdate($table,$FieldList,$options=array()) {
+ $sql = array();
+ $force = false;
+ $db = &DB();
+
+ # Transition until all calls to sqlUpdate() are changed
+ # @todo To deprecate
+ if (func_num_args() >= 4) {
+ $args = func_get_args();
+ $db = array_shift($args);
+ $table = array_shift($args);
+ $FieldList = array_shift($args); if (! is_array($FieldList)) $FieldList=array($FieldList);
+ $options['where'] = array_shift($args);
+ $options['force'] = count($args) ? array_shift($args) : false;
+ }
+
+ if (isset($options['force']))
+ $force = $options['force'];
+ if (isset($options['where']))
+ $sql['where'] = $options['where'];
+
+ $rs = $db->Execute(sqlSelect($table,'*',$sql));
+ return $db->GetUpdateSQL($rs,$FieldList,$force,get_magic_quotes_gpc());
+}
+
+/**
+ * Generate SQL to select records from the database
+ */
+function sqlSelect($TableList,$FieldList,$sql=array()) {
+ # Transition until all calls to sqlSelect() are changed
+ # @todo To deprecate
+ if (func_num_args() >= 4) {
+ $sql = array();
+
+ $args = func_get_args();
+ $db = array_shift($args);
+ $TableList = array_shift($args);
+ $FieldList = array_shift($args);
+ $sql['where'] = array_shift($args);
+ $sql['orderby'] = count($args) ? array_shift($args) : '';
+ $sql['limit'] = count($args) ? array_shift($args) : 0;
+ $sql['distinct'] = count($args) ? array_shift($args) : false;
+ $sql['groupby'] = count($args) ? array_shift($args) : '';
+ }
+
+ # Table(s)
+ if (is_array($TableList)) {
+ $tbarr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V');
+ $table = '';
+
+ $i = 0;
+ foreach ($TableList as $index => $value) {
+ if ($i++>0)
+ $table .= ',';
+
+ $table .= sprintf('%s%s AS %s',AGILE_DB_PREFIX,$value,$tbarr[$index]);
}
} else {
$table = AGILE_DB_PREFIX.$TableList;
}
- ### Field(s)
- if(is_array($FieldList)) {
- $fields = '';
- for($i=0;$i0)
- $fields .= ",".$FieldList[$i];
- else
- $fields .= $FieldList[$i];
- }
- } else {
+ # Field(s)
+ if (isset($sql['distinct']) && $sql['distinct'])
+ $fields = 'DISTINCT '.$FieldList;
+ else
$fields = $FieldList;
- }
- ### Condition(s)
- $where = sqlConditions( $db, $Conditions, $TableList);
+ # Condition(s)
+ $where = sqlConditions($db,$sql['where'],$TableList);
- ### Order By
- if(!empty($Order)) {
- $where .= " ORDER BY $Order ";
- }
+ $line = '';
+ # Group By
+ if (isset($sql['groupby']) && $sql['groupby'])
+ $line .= sprintf(' GROUP BY %s',$sql['groupby']);
- ### Group By
- if(!empty($GroupBy)) {
- $where .= " GROUP BY $GroupBy ";
- }
+ # Order By
+ if (isset($sql['orderby']) && $sql['orderby'])
+ $line .= sprintf(' ORDER BY %s',$sql['orderby']);
- $where = str_replace('{p}', AGILE_DB_PREFIX, $where );
+ # Limit
+ if (isset($sql['limit']) && $sql['limit'])
+ $line .= 'LIMIT '.$sql['limit'];
- if(!empty($DISTINCT)) $DISTINCT = 'DISTINCT';
+ $SQL = sprintf('SELECT %s FROM %s %s %s',$fields,$table,$where,$line);
- return "SELECT $DISTINCT $fields FROM $table $where";
+ if (isset($sql['debug']))
+ printf('%s ',$SQL);
+
+ return $SQL;
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/database_add.inc.php b/modules/core/database_add.inc.php
index 16f8a5ab..17d00d53 100644
--- a/modules/core/database_add.inc.php
+++ b/modules/core/database_add.inc.php
@@ -1,216 +1,239 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.94
+ * @subpackage Core
*/
-
-function CORE_database_add($VAR, $construct, $type)
-{
+
+/**
+ * The main AgileBill CORE Database ADD Method
+ *
+ * @uses CORE_validate
+ * @uses CORE_static_var
+ * @uses CORE_trigger
+ */
+
+function CORE_database_add($VAR,$construct,$type) {
global $C_translate;
- # set the field list for this method:
- $arr = $construct->method["$type"];
+ # Temp during code rework
+ if (! is_array($construct->val_error))
+ $construct->val_error = array();
- # define the validation class
- include_once(PATH_CORE . 'validate.inc.php');
- $validate = new CORE_validate;
+ # Set the field list for this method
+ $arr = $construct->method[$type];
+
+ # Define the validation class
+ include_once(PATH_CORE.'validate.inc.php');
+ $validate = new CORE_validate($VAR,$construct->module);
$construct->validated = true;
+ # Quick Validation to see if we have too many variables.
+ foreach ($VAR as $field_name => $value)
+ if (preg_match("/^{$construct->module}_/",$field_name))
+ if (! in_array(preg_replace("/^{$construct->module}_/",'',$field_name),$arr))
+ array_push($construct->val_error,array(
+ 'field'=>sprintf('%s_%s',$construct->table,$field_name),
+ 'field_trans'=>$field_name,
+ 'error'=>sprintf('WARNING: Variable passed to %s but it will be ignored.',__METHOD__),
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
- ####################################################################
- # loop through the field list to validate the required fields
- ####################################################################
+ # Quick Validation to see if we are missing variables.
+ foreach ($construct->method[$type] as $field_name) {
+ $field_var = sprintf('%s_%s',$construct->module,$field_name);
- while (list ($key, $value) = each ($arr))
- {
- # get the field value
- $field_var = $construct->module . '_' . $value;
- $field_name = $value;
- $construct->validate = true;
+ if (! array_key_exists($field_var,$VAR))
+ array_push($construct->val_error,array(
+ 'field'=>$field_var,
+ 'field_trans'=>$field_name,
+ 'error'=>sprintf('WARNING: Variable NOT passed to %s.',__METHOD__),
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
+ }
- ####################################################################
- # perform any field validation...
- ####################################################################
+ # Perform each field validation
+ while (list($key,$field_name) = each($arr)) {
+ # Get the field value
+ $field_var = sprintf('%s_%s',$construct->module,$field_name);
- # check if this value is unique
- if(isset($construct->field["$value"]["unique"]) && isset($VAR["$field_var"]))
- {
- if(!$validate->validate_unique($construct->table, $field_name, "record_id", $VAR["$field_var"]))
- {
+ # Check if this value is unique
+ if (isset($construct->field[$field_name]['unique']) && isset($VAR[$field_var])) {
+ if (! $validate->validate_unique($construct->table,$field_name,'record_id',$VAR[$field_var])) {
$construct->validated = false;
- $construct->val_error[] = array('field' => $construct->table . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""), # translate
- 'error' => $C_translate->translate('validate_unique',"", ""));
+
+ array_push($construct->val_error,array(
+ 'field'=>sprintf('%s_%s',$construct->module,$field_name),
+ 'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
+ 'error'=>$C_translate->translate('validate_unique','',''),
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
}
}
- # check if the submitted value meets the specifed requirements
- if(isset($construct->field["$value"]["validate"]))
- {
- if(isset($VAR["$field_var"]))
- {
- if($VAR["$field_var"] != '')
- {
- if(!$validate->validate($field_name, $construct->field["$value"], $VAR["$field_var"], $construct->field["$value"]["validate"]))
- {
- $construct->validated = false;
- $construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
- 'error' => $validate->error["$field_name"] );
- }
- }
- else
- {
+ # Check if the submitted value meets the specifed requirements
+ if (isset($construct->field[$field_name]['validate'])) {
+ if (isset($VAR[$field_var]) && ($VAR[$field_var] != '')) {
+ if (! $validate->validate($field_name,$construct->field[$field_name],$VAR[$field_var],$construct->field[$field_name]['validate'])) {
$construct->validated = false;
- $construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
- 'error' => $C_translate->translate('validate_any',"", ""));
+
+ array_push($construct->val_error,array(
+ 'field'=>sprintf('%s_%s',$construct->module,$field_name),
+ 'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
+ 'error'=>$validate->error[$field_name],
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
}
- }
- else
- {
+
+ } else {
$construct->validated = false;
- $construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
- 'error' => $C_translate->translate('validate_any',"", ""));
+
+ array_push($construct->val_error,array(
+ 'field'=>sprintf('%s_%s',$construct->module,$field_name),
+ 'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
+ 'error'=>$C_translate->translate('validate_any','',''),
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
}
}
}
+ # Get required static_vars and validate them
+ require_once(PATH_CORE.'static_var.inc.php');
+ $static_var = new CORE_static_var;
- ####################################################################
- # If validation was failed, skip the db insert &
- # set the errors & origonal fields as Smarty objects,
- # and change the page to be loaded.
- ####################################################################
+ $all_error = $static_var->validate_form($construct->module,$construct->val_error);
- if(!$construct->validated)
- {
- global $smarty;
+ if ($all_error != false && gettype($all_error) == 'array')
+ $construct->validated = false;
+ else
+ $construct->validated = true;
- # set the errors as a Smarty Object
- $smarty->assign('form_validation', $construct->val_error);
+ /* If validation has failed, skip the db insert & set the errors & original fields as Smarty objects,
+ and change the page to be loaded.*/
+ if (! $construct->validated) {
+ global $smarty;
- # set the page to be loaded
- if(!defined("FORCE_PAGE"))
- {
- define('FORCE_PAGE', $VAR['_page_current']);
+ # Set the errors as a Smarty Object
+ $smarty->assign('form_validation',$construct->val_error);
+
+ # Set the page to be loaded
+ if (! defined('FORCE_PAGE'))
+ define('FORCE_PAGE',$VAR['_page_current']);
+
+ # Define any triggers
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
}
- # define any triggers
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
- }
-
- # strip slashes
+ # Strip slashes
global $C_vars;
$C_vars->strip_slashes_all();
+
return false;
- }
- else
- {
- # begin the new database class:
+
+ } else {
+ # Begin the new database class
$db = &DB();
- # loop through the field list to create the sql queries
- $field_list = '';
- $i = 0;
+ # Loop through the field list to create the sql queries
+ $field_list = array();
reset($arr);
- while (list ($key, $value) = each ($arr))
- {
- # get the field value
- $field_var = $construct->module . '_' . $value;
- $field_name = $value;
- if(isset($VAR["$field_var"]))
- {
- # check if html allowed:
- if(@$construct->field["$value"]["html"] != 1 && !is_array($VAR["$field_var"]))
- {
- $insert_value = htmlspecialchars($VAR["$field_var"]);
- } else {
- $insert_value = $VAR["$field_var"];
- }
+ while (list($key,$field_name) = each($arr)) {
+ # Get the field value
+ $field_var = sprintf('%s_%s',$construct->module,$field_name);
- # perform data conversions
- if(isset( $construct->field["$value"]["convert"] ))
- $insert_value = $validate->convert($field_name, $insert_value, $construct->field["$value"]["convert"]);
+ if (isset($VAR[$field_var])) {
+ # Check if HTML allowed
+ if (@$construct->field[$field_name]['html'] != 1 && ! is_array($VAR[$field_var]))
+ $insert_value = htmlspecialchars($VAR[$field_var]);
+ else
+ $insert_value = $VAR[$field_var];
- # create the sql statement
- if(!is_null($insert_value))
- $field_list .= ", " . $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
- }
- }
+ # Perform data conversions
+ if (isset($construct->field[$field_name]['convert']))
+ $insert_value = $validate->convert($field_name,$insert_value,$construct->field[$field_name]['convert']);
- # add a comma before the site_id if needed
- if($field_list != '')
- {
- $field_list .= ',';
- }
-
- # determine the record id:
- $construct->record_id = $db->GenID(AGILE_DB_PREFIX . "" . $construct->table.'_id');
-
- # define the new ID as a constant
- define(strtoupper('NEW_RECORD_'.$construct->table.'_ID'), $construct->record_id);
-
- # generate the full query
- $q = "INSERT INTO ".AGILE_DB_PREFIX."$construct->table
- SET
- id = ". $db->qstr($construct->record_id)."
- $field_list
- site_id = " . $db->qstr(DEFAULT_SITE);
-
- # execute the query
- $result = $db->Execute($q);
-
- ## echo $q;
-
- # error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('database.inc.php','add', $db->ErrorMsg());
-
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
- return false;
+ # Create the sql statement
+ if (! is_null($insert_value))
+ $field_list[$field_name] = $insert_value;
}
}
- # define any triggers:
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 1, $VAR);
+ # Check and see if we have some default fields
+ foreach (array('date_orig','date_last') as $field_name) {
+ $field_var = sprintf('%s_%s',$construct->module,$field_name);
+
+ if (isset($construct->field[$field_name]) && ! isset($VAR[$field_var]))
+ if (isset($construct->field[$field_name]['convert']))
+ $field_list[$field_name] = $validate->convert($field_name,time(),$construct->field[$field_name]['convert']);
+ else
+ $field_list[$field_name] = time();
}
- global $VAR;
- $VAR["id"] = $construct->record_id;
- @$redirect_page = $VAR['_page'];
- if(isset($VAR["_escape"]) || isset($VAR["_escape_next"])) $_escape = '&_escape=1&_escape_next=1';
- define('REDIRECT_PAGE', '?_page=' . $redirect_page . '&id=' . $construct->record_id . '' . @$_escape);
+ # Determine the record id
+ $construct->record_id = $db->GenID(AGILE_DB_PREFIX.$construct->table.'_id');
+
+ # Define the new ID as a constant
+ define(strtoupper(sprintf('NEW_RECORD_%s_ID',$construct->table)),$construct->record_id);
+
+ # Execute the query
+ $result = $db->Execute(sqlInsert($db,$construct->table,$field_list,$construct->record_id));
+
+ # Error reporting
+ if ($result === false) {
+ global $C_debug;
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
+ }
+
+ return false;
+ }
+
+ # Define any triggers
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],1,$VAR);
+ }
+
+ # Insert the static vars
+ $static_var->add($VAR,$construct->module,$construct->record_id);
+
+ $_escape = '';
+ if (isset($VAR['_escape']) || isset($VAR['_escape_next']))
+ $_escape = '&_escape=1&_escape_next=1';
+
+ if (! isset($VAR['_noredirect']))
+ define('REDIRECT_PAGE',sprintf('?_page=%s&id=%s%s',$VAR['_page'],$construct->record_id,$_escape));
+
return $construct->record_id;
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/database_delete.inc.php b/modules/core/database_delete.inc.php
index d7dec3ca..53e907ee 100644
--- a/modules/core/database_delete.inc.php
+++ b/modules/core/database_delete.inc.php
@@ -1,69 +1,58 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
*/
-
-function CORE_database_delete($VAR, &$construct, $type)
-{
- global $C_debug, $C_translate;
- # set the id
- $id = $construct->table . '_id';
+/**
+ * The main AgileBill CORE Database DELETE Method
+ *
+ * @package AgileBill
+ * @subpackage Core:Database
+ * @uses CORE_Trigger
+ */
- # generate the full query
- $q = "DELETE FROM
- ".AGILE_DB_PREFIX."$construct->table
- WHERE
- id = '".$db->qstr($VAR["id"], get_magic_quotes_gpc())."'
- AND
- site_id = '" . DEFAULT_SITE . "'";
+function CORE_database_delete($VAR,$construct,$type) {
+ global $C_debug,$C_translate;
- # execute the query
$db = &DB();
- $result = $db->Execute($q);
+
+ # Execute the SQL
+ $result = $db->Execute(sqlDelete($db,$construct->table,array('id'=>$VAR['id'])));
# Alert
- $C_debug->value["id"] = $VAR[$id];
- $C_debug->value["module_name"] = $C_translate->translate('menu',$construct->module,"");
- $alert = $C_translate->translate('alert_delete_id',"","");
- $C_debug->alert($alert);
+ $C_debug->value['id'] = $VAR[$construct->table.'_id'];
+ $C_debug->value['module_name'] = $C_translate->translate('menu',$construct->module,'');
+ $C_debug->alert($C_translate->translate('alert_delete_id','',''));
# error reporting
- if ($result === false)
- {
+ if ($result === false) {
global $C_debug;
- $C_debug->error('database.inc.php','delete', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+ }
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
- }
- } else {
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
- }
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/database_mass_delete.inc.php b/modules/core/database_mass_delete.inc.php
index 05b4f793..8e2fd804 100644
--- a/modules/core/database_mass_delete.inc.php
+++ b/modules/core/database_mass_delete.inc.php
@@ -1,141 +1,105 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-function CORE_database_mass_delete($VAR, &$construct, $type)
-{
+
+/**
+ * The main AgileBill CORE Database MASS DELETE Method
+ *
+ * @uses CORE_trigger
+ */
+
+function CORE_database_mass_delete($VAR,$construct,$type) {
+ global $C_auth,$C_debug;
+
$db = &DB();
- # set the id
- $id = $construct->table . '_id';
- # generate the list of ID's
- $id_list = '';
- $ii=0;
+ if (isset($VAR['delete_id']))
+ $ids = explode(',',preg_replace('/,$/','',$VAR['delete_id']));
+ elseif (isset($VAR['id']))
+ $ids = explode(',',preg_replace('/,$/','',$VAR['id']));
- if(isset($VAR["delete_id"]))
- {
- $id = explode(',',$VAR["delete_id"]);
- }
- elseif (isset($VAR["id"]))
- {
- $id = explode(',',$VAR["id"]);
- }
-
- for($i=0; $iqstr($id[$i], get_magic_quotes_gpc()) . " ";
- $ii++;
- }
- else
- {
- $id_list .= " OR id = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- $ii++;
- }
- }
- }
-
-
- if($ii>0)
- {
- # generate the full query
- $q = "DELETE FROM
- ".AGILE_DB_PREFIX."$construct->table
- WHERE
- $id_list
- AND
- site_id = '" . DEFAULT_SITE . "'";
- # execute the query
- $result = $db->Execute($q);
-
-
- # error reporting
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('database.inc.php','mass_delete', $db->ErrorMsg());
-
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
- }
+ # Check and see if the user is authorised to delete this records
+ foreach ($ids as $i => $id) {
+ $groups = $db->Execute(sqlSelect($db,'account_group','group_id',array('account_id'=>$id),'group_id'));
+ $group = array();
+ while (! $groups->EOF) {
+ array_push($group,$groups->fields['group_id']);
+ $groups->MoveNext();
}
- else
- {
+ # Verify the user has access to view this account
+ foreach ($group as $gid) {
+ if (! $C_auth->auth_group_by_id($gid)) {
+ unset($ids[$i]);
+ break;
+ }
+ }
+ }
+ # Nothing to delete
+ if (! count($ids))
+ return false;
- ### Delete any associated records:
- if(isset($construct->associated_DELETE))
- {
+ # Execute the query
+ $result = $db->Execute(sqlDelete($db,$construct->table,array('id'=>$ids)));
- for($ii=0; $iiassociated_DELETE); $ii++)
- {
- $id_list = '';
- for($i=0; $iassociated_DELETE[$ii]["field"] ." = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- }
- else
- {
- $id_list .= " OR " . $construct->associated_DELETE[$ii]["field"] . " = " . $db->qstr($id[$i], get_magic_quotes_gpc()) . " ";
- }
- }
- }
+ # Error reporting
+ if ($result === false) {
+ $C_debug->error(__FILE__,__METHOD__, $db->ErrorMsg());
- # generate the full query
- $q = "DELETE FROM
- ".AGILE_DB_PREFIX."". $construct->associated_DELETE[$ii]["table"] . "
- WHERE
- $id_list
- AND
- site_id = '" . DEFAULT_SITE . "'";
- # execute the query
- $result = $db->Execute($q);
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
+ }
+
+ } else {
+ # Delete any associated records
+ if (isset($construct->associated_DELETE) && is_array($construct->associated_DELETE) && count($construct->associated_DELETE)) {
+ foreach ($construct->associated_DELETE as $assoc) {
+ $db->Execute(sqlDelete($db,$assoc['table'],array($assoc['field']=>$ids)));
+
+ # Alert delete message
+ if (! defined('AJAX')) {
+ global $C_translate;
+
+ $C_translate->value['CORE']['module_name'] = $C_translate->translate('name',$construct->module,'');
+ $message = $C_translate->translate('alert_delete_ids','CORE','');
+ $message = str_replace('%%module_name%%','', $message);
+ $C_debug->alert($message);
+ }
+
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],1,$VAR);
}
}
-
- # Alert delete message
- if(!defined('AJAX')) {
- global $C_debug, $C_translate;
- $C_translate->value["CORE"]["module_name"] = $C_translate->translate('name',$construct->module,"");
- $message = $C_translate->translate('alert_delete_ids',"CORE","");
- $message = ereg_replace('%%module_name%%','', $message);
- $C_debug->alert($message);
- }
-
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 1, $VAR);
- }
}
}
-}
-?>
\ No newline at end of file
+
+ return $result;
+}
+?>
diff --git a/modules/core/database_search.inc.php b/modules/core/database_search.inc.php
index aab78040..3cf9a6b6 100644
--- a/modules/core/database_search.inc.php
+++ b/modules/core/database_search.inc.php
@@ -1,316 +1,282 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-function CORE_database_search($VAR, &$construct, $type)
-{
- $db = &DB();
- include_once(PATH_CORE . 'validate.inc.php');
+
+/**
+ * The main AgileBill CORE Database SEARCH Method
+ *
+ * @uses CORE_validate
+ * @uses CORE_trigger
+ * @uses CORE_search
+ */
+
+function CORE_database_search($VAR,$construct,$type) {
+ global $C_list;
+
+ include_once(PATH_CORE.'validate.inc.php');
$validate = new CORE_validate;
- # set the search criteria array
+ $db = &DB();
+
+ # Set the search criteria array
$arr = $VAR;
- # loop through the submitted field_names to get the WHERE statement
+ # Loop through the submitted field_names to get the WHERE statement
$where_list = '';
$i=0;
- while (list ($key, $value) = each ($arr))
- {
- if($i == 0)
- {
- if($value != '')
- {
- $pat = "^" . $construct->module . "_";
- if(eregi($pat, $key))
- {
- $field = eregi_replace($pat,"",$key);
- if(eregi('%',$value))
- {
- # do any data conversion for this field (date, encrypt, etc...)
- if(isset($construct->field["$field"]["convert"]))
- {
- $value = $validate->convert($field, $value, $construct->field["$field"]["convert"]);
- }
+ $pat = sprintf('/^%s_/',$construct->module);
+ while (list($key,$value) = each($arr)) {
+ if ($value != '') {
+ if (preg_match($pat,$key)) {
+ $field = preg_replace($pat,'',$key);
- $where_list .= " WHERE " . $field . " LIKE " . $db->qstr($value, get_magic_quotes_gpc());
- $i++;
- }
+ if (! is_array($value) && preg_match('/%/',$value)) {
+ # Do any data conversion for this field (date, encrypt, etc...)
+ if (isset($construct->field[$field]['convert']))
+ $value = $validate->convert($field,$value,$construct->field[$field]['convert']);
+
+ if ($i)
+ $where_list .= sprintf(' AND %s LIKE %s ',$field,$db->qstr($value,get_magic_quotes_gpc()));
else
- {
- # check if array
- if(is_array($value))
- {
- for($i_arr=0; $i_arr < count($value); $i_arr++)
- {
- if($value["$i_arr"] != '')
- {
- # determine any field options (=, >, <, etc...)
- $f_opt = '=';
- $pat_field = $construct->module.'_'.$field;
- $VAR['field_option']["$pat_field"]["$i_arr"];
- if(isset($VAR['field_option']["$pat_field"]["$i_arr"]))
- {
- $f_opt = $VAR['field_option']["$pat_field"]["$i_arr"];
- # error checking, safety precaution
- if($f_opt != '=' && $f_opt != '>' && $f_opt != '<' && $f_opt != '>=' && $f_opt != '<=' && $f_opt != '!=')
- $f_opt = '=';
- }
+ $where_list .= sprintf(' WHERE %s LIKE %s',$field,$db->qstr($value,get_magic_quotes_gpc()));
- # do any data conversion for this field (date, encrypt, etc...)
- if(isset($construct->field["$field"]["convert"]))
- {
- $value["$i_arr"] = $validate->convert($field, $value["$i_arr"], $construct->field["$field"]["convert"]);
- }
+ $i++;
+ } else {
+ # Check if array
+ if (is_array($value)) {
+ for ($i_arr=0; $i_arr, <, etc...)
+ $f_opt = '=';
+ $pat_field = sprintf('%s_%s',$construct->module,$field);
- if($i_arr == 0)
- {
- $where_list .= " WHERE " . $field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
- $i++;
- }
- else
- {
- $where_list .= " AND " . $field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
- $i++;
- }
- }
+ if (isset($VAR['field_option'][$pat_field][$i_arr])) {
+ $f_opt = $VAR['field_option'][$pat_field][$i_arr];
+ # Error checking, safety precaution
+ if (! in_array($f_opt,array('=','>','<','>=','<=','!=')))
+ $f_opt = '=';
+ }
+
+ # Do any data conversion for this field (date, encrypt, etc...)
+ if (isset($construct->field[$field]['convert']))
+ $value[$i_arr] = $validate->convert($field,$value[$i_arr],$construct->field[$field]['convert']);
+
+ if (($i_arr == 0) && ($i==0))
+ $where_list .= sprintf(' WHERE %s %s %s',$field,$f_opt,$db->qstr($value[$i_arr],get_magic_quotes_gpc()));
+ else
+ $where_list .= sprintf(' AND %s %s %s',$field,$f_opt,$db->qstr($value[$i_arr],get_magic_quotes_gpc()));
+
+ $i++;
}
}
+
+ } else {
+ if ($i)
+ $where_list .= sprintf(' AND %s=%s ',$field,$db->qstr($value,get_magic_quotes_gpc()));
else
- {
- $where_list .= " WHERE " . $field . " = " . $db->qstr($value, get_magic_quotes_gpc());
- $i++;
- }
- }
- }
- }
- }
- else
- {
- if($value != '')
- {
- $pat = "^" . $construct->module . "_";
- if(eregi($pat, $key))
- {
- $field = eregi_replace($pat,"",$key);
- if(eregi('%',$value))
- {
- # do any data conversion for this field (date, encrypt, etc...)
- if(isset($construct->field["$field"]["convert"]))
- {
- $value = $validate->convert($field, $value, $construct->field["$field"]["convert"]);
- }
+ $where_list .= sprintf(' WHERE %s=%s',$field,$db->qstr($value,get_magic_quotes_gpc()));
- $where_list .= " AND " . $field . " LIKE " . $db->qstr($value, get_magic_quotes_gpc());
- $i++;
- }
- else
- {
- # check if array
- if(is_array($value))
- {
- for($i_arr=0; $i_arr < count($value); $i_arr++)
- {
- if($value["$i_arr"] != '')
- {
- # determine any field options (=, >, <, etc...)
- $f_opt = '=';
- $pat_field = $construct->module.'_'.$field;
- if(isset($VAR['field_option']["$pat_field"]["$i_arr"]))
- {
- $f_opt = $VAR['field_option']["$pat_field"]["$i_arr"];
-
- # error checking, safety precaution
- if($f_opt != '=' && $f_opt != '>' && $f_opt != '<' && $f_opt != '>=' && $f_opt != '<=' && $f_opt != '!=')
- $f_opt = '=';
- }
-
- # do any data conversion for this field (date, encrypt, etc...)
- if(isset($construct->field["$field"]["convert"]))
- {
- $value["$i_arr"] = $validate->convert($field, $value["$i_arr"], $construct->field["$field"]["convert"]);
- }
-
- $where_list .= " AND " . $field . " $f_opt " . $db->qstr($value["$i_arr"], get_magic_quotes_gpc());
- $i++;
- }
- }
- }
- else
- {
- $where_list .= " AND " . $field . " = ". $db->qstr($value, get_magic_quotes_gpc());
- $i++;
- }
+ $i++;
}
}
}
}
}
+ # Some table joins
+ $join_table = '';
+ if (isset($VAR['join']) && is_array($VAR['join']))
+ foreach ($VAR['join'] as $table => $joins)
+ if ($C_list->is_installed($table)) {
- #### finalize the WHERE statement
- if($where_list == '')
- {
+ include_once(PATH_MODULES.sprintf('%s/%s.inc.php',$table,$table));
+ $join = new $table;
+
+ if (method_exists($join,'sql_join')) {
+ foreach ($joins as $jointable => $id)
+ $q_join .= $join->sql_join($jointable,$id);
+
+ $join_table .= sprintf(',%s%s',AGILE_DB_PREFIX,$jointable);
+ }
+
+ if ($where_list)
+ $where_list .= sprintf(' AND %s',$q_join);
+ else
+ $where_list .= sprintf(' WHERE %s',$q_join);
+ }
+
+ # Finalize the WHERE statement
+ if ($where_list == '')
$where_list .= ' WHERE ';
- }
else
- {
$where_list .= ' AND ';
- }
-
- # get limit type
- if(isset($VAR['limit']))
- {
+ # Get limit type
+ if (isset($VAR['limit']))
$limit = $VAR['limit'];
- }
else
- {
$limit = $construct->limit;
- }
- # get order by
- if(isset($VAR['order_by']))
- {
+ # Get order by
+ if (isset($VAR['order_by']))
$order_by = $VAR['order_by'];
- }
else
- {
$order_by = $construct->order_by;
- }
- ### Get any addition fields to select:
- if(isset($construct->custom_EXP))
- {
- for($ei=0; $eicustom_EXP); $ei++)
- {
- if($ei == 0)
- $field_list = "," . $construct->custom_EXP[$ei]['field'];
+ # Get any addition fields to select:
+ if (isset($construct->custom_EXP))
+ for ($ei=1; $eicustom_EXP); $ei++)
+ $field_list = sprintf(',%s',$construct->custom_EXP[$ei]['field']);
+
+ # Get any static vars to search
+ $join_list = '';
+ $pre = AGILE_DB_PREFIX;
+ if (! empty($VAR['static_relation']) && count($VAR['static_relation']>0)) {
+ while (list($idx,$value) = each($VAR['static_relation'])) {
+ if ($value != '') {
+ $join_list .= sprintf(" INNER JOIN %sstatic_var_record AS s%s ON (s%s.record_id=%s%s.id AND s%s.static_var_relation_id='%s' AND s%s.site_id=%s AND",
+ $pre,$idx,$idx,$pre,$this->table,$idx,$idx,$idx,$db->qstr(DEFAULT_SITE));
+
+ if(preg_match('/%/',$value))
+ $join_list .= sprintf(' s%s.value LIKE %s',$idx,$db->qstr($VAR['static_relation'][$idx]));
+ else
+ $join_list .= sprintf(' s%s.value = %s',$idx,$db->qstr($VAR['static_relation'][$idx]));
+
+ $join_list .= ') ';
+ }
}
}
+/*
+ # standard where list
+ $q .= $join_list . $where_list ." ".AGILE_DB_PREFIX."account.site_id = " . $db->qstr(DEFAULT_SITE);
+
+ # Code for member group
+ if(!empty($VAR['account_group'])) {
+ $q .= " AND ".AGILE_DB_PREFIX."account_group.group_id = " . $db->qstr($VAR['account_group'])."
+ AND ".AGILE_DB_PREFIX."account_group.site_id = " . $db->qstr(DEFAULT_SITE);
+ }
+ if(!empty($VAR['account_group'])) {
+ $q_save .= " LEFT JOIN ".AGILE_DB_PREFIX."account_group ON ".AGILE_DB_PREFIX."account_group.account_id = ".AGILE_DB_PREFIX."account.id ";
+
+ if(!empty($join_list))
+ $q_save .= $join_list;
+
+ $q_save .= $where_list ." %%whereList%% ";
+ $q_save .= AGILE_DB_PREFIX."account_group.group_id = " . $db->qstr($VAR['account_group'])." AND ";
+ } else {
+ if(!empty($join_list))
+ $q_save .= $join_list;
+
+ $q_save .= $where_list ." %%whereList%% ";
+ }
+*/
+
# generate the full query
- $q = "SELECT id".$field_list." FROM
- ".AGILE_DB_PREFIX."$construct->table
- $where_list
- site_id = '" . DEFAULT_SITE . "'";
+ $q = sprintf('SELECT %s%s.id AS id%s FROM %s%s %s %s %s%s.site_id=%s',
+ AGILE_DB_PREFIX,$construct->table,$field_list,
+ AGILE_DB_PREFIX,$construct->table,$join_table,
+ $where_list,AGILE_DB_PREFIX,$construct->table,DEFAULT_SITE);
+ $q_save = "SELECT %%fieldList%% FROM %%tableList%% $join_table".$where_list." %%whereList%% ";
+ $result = $db->Execute($q);
- $q_save = "SELECT %%fieldList%% FROM %%tableList%% ".$where_list." %%whereList%% ";
-
-
-
- $result = $db->Execute($q);
-
-
- //////////////// DEBUG ////
- #echo "$q ";
- #exit;
-
- # error reporting
- if ($result === false)
- {
+ # Error reporting
+ if ($result === false) {
global $C_debug;
- $C_debug->error('database.inc.php','search', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
}
- return;
+ return;
}
- # get the result count:
+ # Get the result count:
$results = $result->RecordCount();
- # get the first record id:
- if($results == 1) $record_id = $result->fields['id'];
+ # Get the first record id:
+ if ($results == 1)
+ $record_id = $result->fields['id'];
- ### Run any custom validation on this result for
- ### this module
- if(isset($construct->custom_EXP))
- {
+ # Run any custom validation on this result for this module
+ if (isset($construct->custom_EXP)) {
$results = 0;
- while(!$result->EOF)
- {
- for($ei=0; $eicustom_EXP); $ei++)
- {
- $field = $construct->custom_EXP[$ei]["field"];
- $value = $construct->custom_EXP[$ei]["value"];
- if($result->fields["$field"] == $value)
- {
- //$result->MoveNext();
+
+ while (! $result->EOF) {
+ for ($ei=0; $eicustom_EXP); $ei++) {
+ $field = $construct->custom_EXP[$ei]['field'];
+ $value = $construct->custom_EXP[$ei]['value'];
+
+ if ($result->fields[$field] == $value) {
$ei = count($construct->custom_EXP);
- $results++;
- }
+ $results++;
+ }
}
+
$result->MoveNext();
}
}
-
- # define the DB vars as a Smarty accessible block
+ # Define the DB vars as a Smarty accessible block
global $smarty;
# Create the definition for fast-forwarding to a single record:
if ($results == 1 && !isset($construct->fast_forward))
- {
- $smarty->assign('record_id', $record_id);
- }
+ $smarty->assign('record_id',$record_id);
# create the search record:
- if($results > 0)
- {
+ if ($results > 0) {
# create the search record
- include_once(PATH_CORE . 'search.inc.php');
+ include_once(PATH_CORE.'search.inc.php');
$search = new CORE_search;
- $arr['module'] = $construct->module;
+ $arr['module'] = $construct->module;
$arr['sql'] = $q_save;
- $arr['limit'] = $limit;
+ $arr['limit'] = $limit;
$arr['order_by']= $order_by;
$arr['results'] = $results;
$search->add($arr);
# define the search id and other parameters for Smarty
- $smarty->assign('search_id', $search->id);
-
+ $smarty->assign('search_id',$search->id);
# page:
- $smarty->assign('page', '1');
-
+ $smarty->assign('page','1');
# limit:
- $smarty->assign('limit', $limit);
-
+ $smarty->assign('limit',$limit);
# order_by:
- $smarty->assign('order_by', $order_by);
+ $smarty->assign('order_by',$order_by);
}
-
# define the result count
- $smarty->assign('results', $results);
+ $smarty->assign('results',$results);
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 1, $VAR);
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+ $trigger->trigger($construct->trigger[$type],1,$VAR);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/database_search_form.inc.php b/modules/core/database_search_form.inc.php
index 7da75866..1fa5cc4e 100644
--- a/modules/core/database_search_form.inc.php
+++ b/modules/core/database_search_form.inc.php
@@ -31,18 +31,20 @@ function CORE_database_search_form($VAR, $construct, $type)
while (list ($key, $value) = each ($arr))
{
$field_list["$i"]['translate'] = $C_translate->translate('field_' . $value, $construct->module, "");
+ if (! $field_list["$i"]['translate'])
+ $field_list["$i"]['translate'] = sprintf('field_%s',$value);
$field_list["$i"]['field'] = $value;
$i++;
}
# define the field list as a Smarty accessible array
- $smarty->assign($construct->module, $field_list);
+ $smarty->assign('field_list',$field_list);
# define the default ORDER BY field
- $smarty->assign($construct->module . '_order_by', $construct->order_by);
+ $smarty->assign('field_order_by',$construct->order_by);
# define the default LIMIT count
- $smarty->assign($construct->module . '_limit', $construct->limit);
+ $smarty->assign('field_limit',$construct->limit);
# define the recent search menu & javascript
include_once(PATH_CORE . 'search.inc.php');
@@ -66,4 +68,4 @@ function CORE_database_search_form($VAR, $construct, $type)
# send the finished SAVED SEARCH JavaScript to Smarty
$smarty->assign($construct->module . "_saved_js", $search->saved_js);
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/database_search_show.inc.php b/modules/core/database_search_show.inc.php
index c6190376..13719354 100644
--- a/modules/core/database_search_show.inc.php
+++ b/modules/core/database_search_show.inc.php
@@ -1,75 +1,72 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-function CORE_database_search_show($VAR, &$construct, $type)
-{
- # set the field list for this method:
+/**
+ * The main AgileBill CORE Database SEARCH_SHOW Method
+ *
+ * @uses CORE_search
+ * @uses CORE_trigger
+ */
+
+function CORE_database_search_show($VAR, &$construct, $type) {
+ # Set the field list for this method:
$arr = $construct->method[$type];
$field_list = '';
+ $construct->linked = array();
+
$i=0;
- while (list ($key, $value) = each ($arr))
- {
- if($i == 0)
- {
- $field_var = $construct->table . '_' . $value;
- $field_list .= AGILE_DB_PREFIX . $construct->table . "." . $value;
+ while (list($key,$value) = each($arr)) {
+ $field_var = sprintf('%s_%s',$construct->table,$value);
- // determine if this record is linked to another table/field
- if($construct->field[$value]["asso_table"] != "")
- {
- $construct->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
- }
- }
+ if ($i == 0)
+ $field_list .= sprintf('%s%s.%s',AGILE_DB_PREFIX,$construct->table,$value);
else
- {
- $field_var = $construct->table . '_' . $value;
- $field_list .= "," . AGILE_DB_PREFIX . $construct->table . "." . $value;
+ $field_list .= sprintf(',%s%s.%s',AGILE_DB_PREFIX,$construct->table,$value);
+
+ # Determine if this record is linked to another table/field
+ if ($construct->field[$value]['asso_table'] != '')
+ array_push($construct->linked,array('field'=>$value,'link_table'=>$construct->field[$value]['asso_table'],'link_field'=>$construct->field[$value]['asso_field']));
- // determine if this record is linked to another table/field
- if($construct->field[$value]["asso_table"] != "")
- {
- $construct->linked[] = array('field' => $value, 'link_table' => $construct->field[$value]["asso_table"], 'link_field' => $construct->field[$value]["asso_field"]);
- }
- }
$i++;
}
-
- # get the search details:
- if(isset($VAR['search_id']))
- {
- include_once(PATH_CORE . 'search.inc.php');
+ # Get the search details:
+ if (isset($VAR['search_id'])) {
+ include_once(PATH_CORE.'search.inc.php');
$search = new CORE_search;
- $search->get($VAR['search_id']);
- }
- else
- {
- # invalid search!
- echo ' The search terms submitted were invalid! '; # translate... # alert
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
+ $search->get($VAR['search_id']);
+
+ } else {
+ # Invalid search!
+ echo ' The search terms submitted were invalid! ';
+
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
}
}
@@ -77,176 +74,179 @@ function CORE_database_search_show($VAR, &$construct, $type)
if ($search->session != SESS && $search->account != SESS_ACCOUNT) {
global $C_debug;
$C_debug->alert('You are not authorized to view this search!');
+
return false;
}
- # get the sort order details:
- if(isset($VAR['order_by']) && $VAR['order_by'] != "")
- {
- $order_by = ' ORDER BY ' . $VAR['order_by'];
- $smarty_order = $VAR['order_by'];
- }
- else
- {
- $order_by = ' ORDER BY ' . $construct->order_by;
- $smarty_order = $search->order_by;
+ # Get the sort order details:
+ if (isset($VAR['order_by']) && $VAR['order_by'] != '') {
+ $order_by = sprintf(' ORDER BY %s',$VAR['order_by']);
+
+ $smarty_order = $VAR['order_by'];
+
+ } else {
+ $order_by = sprintf(' ORDER BY %s',$construct->order_by);
+ $smarty_order = $search->order_by;
}
-
- # determine the sort order
- if(isset($VAR['desc'])) {
+ # Determine the sort order
+ if (isset($VAR['desc'])) {
$order_by .= ' DESC';
$smarty_sort = 'desc=';
- } else if(isset($VAR['asc'])) {
+
+ } elseif (isset($VAR['asc'])) {
$order_by .= ' ASC';
$smarty_sort = 'asc=';
+
} else {
- if (!eregi('date',$smarty_order)) {
+ if (! preg_match('/date/',$smarty_order)) {
$order_by .= ' ASC';
$smarty_sort = 'asc=';
- } else {
+
+ } else {
$order_by .= ' DESC';
$smarty_sort = 'desc=';
}
- }
+ }
+ # Generate the full query
+ $db = &DB();
- # generate the full query
- $db = &DB();
- $q = eregi_replace("%%fieldList%%", $field_list, $search->sql);
- $q = eregi_replace("%%tableList%%", AGILE_DB_PREFIX.$construct->table, $q);
- $q = eregi_replace("%%whereList%%", "", $q);
- $q .= " site_id = '" . DEFAULT_SITE . "'";
+ $q = str_replace('%%fieldList%%',$field_list,$search->sql);
+ $q = str_replace('%%tableList%%',AGILE_DB_PREFIX.$construct->table,$q);
+ $q = str_replace('%%whereList%%','',$q);
+
+ $q .= sprintf(' %s.site_id = %s',AGILE_DB_PREFIX.$construct->table,DEFAULT_SITE);
$q .= $order_by;
- ///////////////////////
+ # Determine the offset & limit
+ $current_page = 1;
+ $offset = -1;
- # determine the offset & limit
- $current_page=1;
- $offset=-1;
- if (!empty($VAR['page'])) $current_page = $VAR['page'];
- if (empty($search->limit)) $search->limit=25;
- if($current_page>1) $offset = (($current_page * $search->limit) - $search->limit);
- $result = $db->SelectLimit($q, $search->limit, $offset);
+ if (! empty($VAR['page']))
+ $current_page = $VAR['page'];
+ if (empty($search->limit))
+ $search->limit=25;
- # error reporting
- if ($result === false)
- {
+ if ($current_page>1)
+ $offset = (($current_page*$search->limit)-$search->limit);
+
+ $result = $db->SelectLimit($q,$search->limit,$offset);
+
+ # Error reporting
+ if ($result === false) {
global $C_debug;
- $C_debug->error('database.inc.php','search', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
}
- return;
+
+ return;
}
+ # Run any custom validation on this result for this module
+ $i = 0;
+ $class_name = true;
+ if (isset($construct->custom_EXP)) {
+ while (! $result->EOF) {
+ for ($ei=0; $eicustom_EXP); $ei++) {
+ $field = $construct->custom_EXP[$ei]['field'];
+ $value = $construct->custom_EXP[$ei]['value'];
- ### Put the results into a smarty accessable array
- ### Run any custom validation on this result for
- ### this module
- if(isset($construct->custom_EXP))
- {
- $i=0;
- $class_name = TRUE;
- $results = 0;
- while(!$result->EOF)
- {
- for($ei=0; $eicustom_EXP); $ei++)
- {
- $field = $construct->custom_EXP[$ei]["field"];
- $value = $construct->custom_EXP[$ei]["value"];
- if($result->fields["$field"] == $value)
- {
+ if ($result->fields[$field] == $value) {
$smart[$i] = $result->fields;
- if($class_name)
- {
+ if ($class_name) {
$smart[$i]['_C'] = 'row1';
- $class_name = FALSE;
+ $class_name = false;
} else {
$smart[$i]['_C'] = 'row2';
- $class_name = TRUE;
- }
- $i++;
+ $class_name = true;
+ }
+
+ $i++;
$ei = count($construct->custom_EXP);
- $results++;
- }
- }
+ }
+ }
+
$result->MoveNext();
}
- }
- else
- {
- $i=0;
- $class_name = TRUE;
- while (!$result->EOF) {
+
+ } else {
+ while (! $result->EOF) {
$smart[$i] = $result->fields;
- if($class_name)
- {
+ if ($class_name) {
$smart[$i]['_C'] = 'row1';
- $class_name = FALSE;
+ $class_name = false;
} else {
$smart[$i]['_C'] = 'row2';
- $class_name = TRUE;
+ $class_name = true;
}
+
$result->MoveNext();
$i++;
}
}
- # get any linked fields
- if($i > 0) {
+ # Get any linked fields
+ if ($i > 0) {
$db_join = new CORE_database;
$construct->result = $db_join->join_fields($smart, $construct->linked);
+
} else {
$construct->result = $smart;
- }
+ }
- # get the result count:
+ # Get the result count:
$results = $result->RecordCount();
# define the DB vars as a Smarty accessible block
global $smarty;
# define the results
- $smarty->assign($construct->table, $construct->result);
- $smarty->assign('page', $VAR['page']);
- $smarty->assign('order', $smarty_order);
- $smarty->assign('sort', $smarty_sort);
- $smarty->assign('limit', $search->limit);
+ $smarty->assign('search_show',$construct->result);
+ $smarty->assign('page',$VAR['page']);
+ $smarty->assign('order',$smarty_order);
+ $smarty->assign('sort',$smarty_sort);
+ $smarty->assign('limit',$search->limit);
$smarty->assign('search_id',$search->id);
- $smarty->assign('results', $search->results);
+ $smarty->assign('results',$search->results);
# get the total pages for this search:
if (empty($search->limit))
$construct->pages = 1;
else
$construct->pages = intval($search->results / $search->limit);
- if ($search->results % $search->limit) $construct->pages++;
- # total pages
- $smarty->assign('pages', $construct->pages);
+ if ($search->results % $search->limit)
+ $construct->pages++;
- # current page
- $smarty->assign('page', $current_page);
- $page_arr = '';
- for($i=0; $i <= $construct->pages; $i++)
- if ($construct->page != $i) $page_arr[] = $i;
+ # Total pages
+ $smarty->assign('pages',$construct->pages);
- # page array for menu
- $smarty->assign('page_arr', $page_arr);
+ # Current page
+ $smarty->assign('page',$current_page);
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 1, $VAR);
- }
- return $construct->result;
+ $page_arr = array();
+ for ($i=0; $i<=$construct->pages; $i++)
+ if ($construct->page != $i)
+ array_push($page_arr,$i);
+
+ # Page array for menu
+ $smarty->assign('page_arr',$page_arr);
+
+ if(isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],1,$VAR);
+ }
+
+ return $construct->result;
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/database_update.inc.php b/modules/core/database_update.inc.php
index 779e0f62..5af4090d 100644
--- a/modules/core/database_update.inc.php
+++ b/modules/core/database_update.inc.php
@@ -1,226 +1,200 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-function CORE_database_update($VAR, &$construct, $type)
-{
+
+/**
+ * The main AgileBill CORE Database UPDATE Method
+ *
+ * @uses CORE_validate
+ * @uses CORE_trigger
+ */
+
+function CORE_database_update($VAR,$construct,$type) {
global $C_translate;
- # set the field list for this method:
- $arr = $construct->method["$type"];
+ # Temp during code rework
+ if (! is_array($construct->val_error))
+ $construct->val_error = array();
- # define the validation class
- include_once(PATH_CORE . 'validate.inc.php');
- $validate = new CORE_validate;
+ # Set the field list for this method
+ $arr = $construct->method[$type];
- $construct->validated = true;
+ # Define the validation class
+ include_once(PATH_CORE.'validate.inc.php');
+ $validate = new CORE_validate($VAR,$construct->module);
+ $construct->validated = true;
- # define this record id
- $id = $VAR[$construct->module . '_id'];
+ # Quick Validation to see if we have too many variables.
+ foreach ($VAR as $field_name => $value)
+ if (preg_match("/^{$construct->module}_/",$field_name))
+ if (! in_array(preg_replace("/^{$construct->module}_/",'',$field_name),$arr))
+ array_push($construct->val_error,array(
+ 'field'=>sprintf('%s_%s',$construct->table,$field_name),
+ 'field_trans'=>$field_name,
+ 'error'=>sprintf('WARNING: Variable passed to %s but it will be ignored.',__METHOD__),
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
- ####################################################################
- # loop through the field list to validate the required fields
- ####################################################################
+ # Define this record id
+ $id = $VAR[$construct->module.'_id'];
- while (list ($key, $value) = each ($arr))
- {
- # get the field value
- $field_var = $construct->module . '_' . $value;
- $field_name = $value;
- $construct->validate = true;
+ # Perform each field validation
+ while (list($key,$field_name) = each($arr)) {
+ # Get the field value
+ $field_var = sprintf('%s_%s',$construct->module,$field_name);
-
- ####################################################################
- # perform any field validation...
- ####################################################################
-
- # check if the conversion type required is not one ignored on updates:
+ # Check if the conversion type required is not one ignored on updates
$ignore_con = false;
- $ignore_convert = Array('sha', 'md5','rc5','crypt');
- for ($ic=0; $ic < count($ignore_convert); $ic++)
- {
- if (isset($construct->field["$value"]["convert"]))
- if ($construct->field["$value"]["convert"] == $ignore_convert[$ic]) $ignore_con = true;
- }
+ $ignore_convert = array('sha','md5','rc5','crypt');
+ for ($ic=0; $icfield[$field_name]['convert']))
+ if ($construct->field[$field_name]['convert'] == $ignore_convert[$ic])
+ $ignore_con = true;
- if(!$ignore_con)
- {
+ if (! $ignore_con) {
# check if this value is unique
- if(isset($construct->field["$value"]["unique"]))
- {
- if(isset($VAR["$field_var"]))
- {
- if(!$validate->validate_unique($construct->table, $field_name, $id, $VAR["$field_var"]))
- {
- $construct->validated = false;
- $construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""), # translate
- 'error' => $C_translate->translate('validate_unique',"", ""));
- }
- }
+ if (isset($construct->field[$field_name]['unique']) && isset($VAR[$field_var])) {
+ if (! $validate->validate_unique($construct->table,$field_name,$id,$VAR[$field_var])) {
+ $construct->validated = false;
+
+ array_push($construct->val_error,array(
+ 'field'=>sprintf('%s_%s',$construct->module,$field_name),
+ 'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
+ 'error'=>$C_translate->translate('validate_unique','',''),
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
+ }
}
- # check if the submitted value meets the specifed requirements
- if(isset($construct->field["$value"]["validate"]))
- {
- if(isset($VAR["$field_var"]))
- {
- if($VAR["$field_var"] != '')
- {
- if(!$validate->validate($field_name, $construct->field["$value"], $VAR["$field_var"], $construct->field["$value"]["validate"]))
- {
- $construct->validated = false;
- $construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
- 'error' => $validate->error["$field_name"] );
- }
- }
- else
- {
+ # Check if the submitted value meets the specifed requirements
+ if (isset($construct->field[$field_name]['validate'])) {
+ if (isset($VAR[$field_var]) && ($VAR[$field_var] != '')) {
+ if (! $validate->validate($field_name,$construct->field[$field_name],$VAR[$field_var],$construct->field[$field_name]['validate'])) {
$construct->validated = false;
- $construct->val_error[] = array('field' => $construct->module . '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
- 'error' => $C_translate->translate('validate_any',"", ""));
+
+ array_push($construct->val_error,array(
+ 'field'=>sprintf('%s_%s',$construct->module,$field_name),
+ 'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
+ 'error'=>$validate->error[$field_name],
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
}
- }
- else
- {
+
+ } else {
$construct->validated = false;
- $construct->val_error[] = array('field' => $construct->module. '_' . $field_name,
- 'field_trans' => $C_translate->translate('field_' . $field_name, $construct->module, ""),
- 'error' => $C_translate->translate('validate_any',"", ""));
+
+ array_push($construct->val_error,array(
+ 'field'=>sprintf('%s_%s',$construct->module,$field_name),
+ 'field_trans'=>$C_translate->translate('field_'.$field_name,$construct->module,''),
+ 'error'=>$C_translate->translate('validate_any','',''),
+ 'method'=>sprintf('%s:%s(%s)',__FILE__,__METHOD__,__LINE__)
+ ));
}
}
}
}
+ /* If validation has failed, skip the db insert & set the errors & original fields as Smarty objects,
+ and change the page to be loaded.*/
+ if (! $construct->validated) {
+ global $smarty;
+ # Set the errors as a Smarty Object
+ $smarty->assign('form_validation',$construct->val_error);
+ # Change the page to be loaded
+ $VAR['_page'] = $construct->module.':view';
- ####################################################################
- # If validation was failed, skip the db insert &
- # set the errors & origonal fields as Smarty objects,
- # and change the page to be loaded.
- ####################################################################
+ # Define any triggers
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
- if(!$construct->validated)
- {
- global $smarty;
-
- # set the errors as a Smarty Object
- $smarty->assign('form_validation', $construct->val_error);
-
- # change the page to be loaded
- global $VAR;
- $VAR['_page'] = $construct->module . ':view';
-
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
}
- # strip slashes
+ # Strip slashes
global $C_vars;
$C_vars->strip_slashes_all();
- return false;
- }
- else
- {
+
+ return false;
+
+ } else {
+ # Begin the new database class
$db = &DB();
- $field_list = '';
- $i = 0;
+
+ # Loop through the field list to create the sql queries
+ $field_list = array();
reset($arr);
- while (list ($key, $value) = each ($arr))
- {
- # get the field value
- $field_var = $construct->module . '_' . $value;
- $field_name = $value;
+ while (list($key,$field_name) = each($arr)) {
+ # Get the field value
+ $field_var = sprintf('%s_%s',$construct->module,$field_name);
- if(isset($VAR["$field_var"]) && $VAR["$field_var"] != 'IGNORE-ARRAY-VALUE')
- {
- # check if html allowed:
- if(@$construct->field["$value"]["html"] != 1 && !is_array($VAR["$field_var"]))
- $insert_value = htmlspecialchars($VAR["$field_var"]);
+ if (isset($VAR[$field_var]) && $VAR[$field_var] != 'IGNORE-ARRAY-VALUE') {
+ # Check if HTML allowed
+ if (@$construct->field[$field_name]['html'] != 1 && ! is_array($VAR[$field_var]))
+ $insert_value = htmlspecialchars($VAR[$field_var]);
else
- $insert_value = $VAR["$field_var"];
+ $insert_value = $VAR[$field_var];
- # perform data conversions
- if(isset($construct->field["$value"]["convert"] ))
- $insert_value = $validate->convert($field_name, $insert_value, $construct->field["$value"]["convert"]);
+ # Perform data conversions
+ if (isset($construct->field[$field_name]['convert']) && trim($construct->field[$field_name]['convert']))
+ $insert_value = $validate->convert($field_name,$insert_value,$construct->field[$field_name]['convert']);
- if($i == 0)
- $field_list .= $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
- else
- $field_list .= ", " . $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
- $i++;
- }
- elseif ( @$construct->field["$value"]["convert"] == "array" && @$VAR["$field_var"] != 'IGNORE-ARRAY-VALUE')
- {
- # Handle blank array string...
- $insert_value = serialize(Array(""));
- if($i == 0)
- $field_list .= $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
- else
- $field_list .= ", " . $value . "=" . $db->qstr($insert_value, get_magic_quotes_gpc());
- $i++;
- }
+ $field_list[$field_name] = $insert_value;
+
+ } elseif (@$construct->field[$field_name]['convert'] == 'array' && @$VAR[$field_var] != 'IGNORE-ARRAY-VALUE')
+ # Handle blank array string
+ $field_list[$field_name] = serialize(array());
}
- # generate the full query
- $q = "UPDATE " . AGILE_DB_PREFIX . "$construct->table SET
- $field_list
- WHERE
- id = ". $db->qstr($id) ."
- AND
- site_id = " . $db->qstr(DEFAULT_SITE);
- # execute the query
- $db = &DB();
- $result = $db->Execute($q);
+ # Execute the query
+ $result = $db->Execute(sqlUpdate($db,$construct->table,$field_list,array('id'=>$id)));
- # echo "$q ";
-
- # error reporting
- if ($result === false)
- {
+ # Error reporting
+ if ($result === false) {
global $C_debug;
- $C_debug->error('database.inc.php','update', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
}
- return false;
+
+ return false;
+
}
- else
- {
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 1, $VAR);
- }
- return true;
+ # Define any triggers
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],1,$VAR);
}
- }
+
+ return true;
+ }
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/database_view.inc.php b/modules/core/database_view.inc.php
index 3927deeb..55810c6e 100644
--- a/modules/core/database_view.inc.php
+++ b/modules/core/database_view.inc.php
@@ -1,170 +1,111 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-function CORE_database_view($VAR, &$construct, $type)
-{
+
+/**
+ * The main AgileBill CORE Database VIEW Method
+ *
+ * This function should only return 1 record.
+ *
+ * @uses CORE_trigger
+ * @uses CORE_static_var
+ */
+
+function CORE_database_view($VAR,$construct,$type) {
+ require_once(PATH_CORE.'static_var.inc.php');
+
+ # Some Validaiton
+ if (! isset($VAR['id']))
+ return;
+
+ # If we have more than 1 entry, then return. Javascript should bring us back with 1 entry to view.
+ if (count(explode(',',preg_replace('/,$/','',$VAR['id']))) > 1)
+ return;
+
+ # Set our db.
$db = &DB();
- # set the field list for this method:
- $arr = $construct->method[$type];
+ $result = $db->Execute(sqlSelect($db,$construct->table,implode(',',$construct->method[$type]),array('id'=>$VAR['id']),$construct->order_by));
- # loop through the field list to create the sql queries
- $field_list = '';
- $i=0;
- while (list ($key, $value) = each ($arr))
- {
- if($i == 0)
- {
- $field_var = $construct->table . '_' . $value;
- $field_list .= $value;
+ # Error reporting
+ if ($result === false) {
+ global $C_debug;
+
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],0,$VAR);
}
- else
- {
- $field_var = $construct->table . '_' . $value;
- $field_list .= "," . $value;
- }
- $i++;
+
+ return;
+
+ # No results:
+ } elseif (! $result->RecordCount()) {
+ global $C_debug;
+ $C_debug->error(__FILE__,__METHOD__,'The selected record does not exist any longer, or your account is not authorized to view it');
+
+ return;
}
- if(isset($VAR["id"]))
- {
- $id = explode(',',$VAR["id"]);
- for($i=0; $iqstr($id[$i])." ";
- $ii++;
- }
- else
- {
- $id_list .= " OR id = " .$db->qstr($id[$i]). " ";
- $ii++;
- }
- }
- }
- }
+ # Get the static vars
+ $static_var = new CORE_static_var;
+ $arr = $static_var->update_form($construct->module,'update',$result->fields['id']);
+ if (is_array($arr))
+ $smart['static_var'] = $arr;
- if($ii>0)
- {
- # generate the full query
- $q = "SELECT
- $field_list
- FROM
- ".AGILE_DB_PREFIX."$construct->table
- WHERE
- $id_list
- AND site_id = '" . DEFAULT_SITE . "'
- ORDER BY $construct->order_by ";
+ # Run any custom validation on this result for this module
+ if (isset($construct->custom_EXP)) {
+ for ($ei=0; $eicustom_EXP); $ei++) {
+ $field = $construct->custom_EXP[$ei]['field'];
+ $value = $construct->custom_EXP[$ei]['value'];
- $result = $db->Execute($q);
+ if ($result->fields[$field] == $value) {
+ $smart = $result->fields;
- ///////////////////////
- # echo $q;
- # echo " " . $db->ErrorMsg();
-
- # error reporting
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('database.inc.php','view', $db->ErrorMsg());
-
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 0, $VAR);
- }
- return;
- }
-
- # put the results into a smarty accessable array
- $i=0;
- $class_name = TRUE;
- while (!$result->EOF)
- {
- ### Run any custom validation on this result for
- ### this module
- if(isset($construct->custom_EXP))
- {
- for($ei=0; $eicustom_EXP); $ei++)
- {
- $field = $construct->custom_EXP[$ei]["field"];
- $value = $construct->custom_EXP[$ei]["value"];
- if($result->fields["$field"] == $value)
- {
- $smart[$i] = $result->fields;
- if($class_name)
- {
- $smart[$i]["i"] = $i;
- } else {
- $smart[$i]["i"] = $i;
- }
- $result->MoveNext();
- $ei = count($construct->custom_EXP);
- $i++;
- }
- }
$result->MoveNext();
- }
- else
- {
- $smart[$i] = $result->fields;
- if($class_name)
- {
- $smart[$i]["i"] = $i;
- } else {
- $smart[$i]["i"] = $i;
- }
- $result->MoveNext();
- $i++;
+ $ei = count($construct->custom_EXP);
}
}
- # get the result count:
- $results = $i;
-
- ### No results:
- if($i == 0)
- {
- global $C_debug;
- $C_debug->error("CORE:database.inc.php", "view()", "The selected record does not
- exist any longer, or your account is not authorized to view it");
- return;
- }
-
- # define the results
- global $smarty;
- $smarty->assign($construct->table, $smart);
- $smarty->assign('results', $search->results);
-
- if(isset($construct->trigger["$type"]))
- {
- include_once(PATH_CORE . 'trigger.inc.php');
- $trigger = new CORE_trigger;
- $trigger->trigger($construct->trigger["$type"], 1, $VAR);
- }
-
- return $smart;
+ } else {
+ $smart = $result->fields;
}
+
+ # Define the results
+ global $smarty;
+ $smarty->assign('record',$smart);
+
+ if (isset($construct->trigger[$type])) {
+ include_once(PATH_CORE.'trigger.inc.php');
+ $trigger = new CORE_trigger;
+
+ $trigger->trigger($construct->trigger[$type],1,$VAR);
+ }
+
+ # Return the retrieved records
+ return $smart;
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/email.inc.php b/modules/core/email.inc.php
index fa78f701..780280af 100644
--- a/modules/core/email.inc.php
+++ b/modules/core/email.inc.php
@@ -1,249 +1,217 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-
-/*
- Email Handler Class
- This class handles the interface to SMPT and Mail() functions.
-
- $arr = Array(
- 'from_html' => 'true/false' (so we know whether to stripslashes or not)
- 'html' => '0/1',
- 'from_name' => '',
- 'from_email' => '',
- 'priority' => '0/1',
- 'to_email' => 'email@email.com',
- 'to_name' => '',
- 'bcc_list' => Array('email@email.com'),
- 'cc_list' => Array('email@email.com'),
- 'subject' => '',
- 'body_text' => '',
- 'body_html' => '',
- 'attachments' => Array(Array('file' => 'file.exe',
- 'data' => 'file data here...'))
- 'server' => 'mail.domain.com',
- 'account' => '',
- 'password' => '');
+/**
+ * The main AgileBill CORE Mail Class
+ *
+ * This class handles the interface to SMTP and Mail() functions.
+ *
+ *
+ * $arr = array(
+ * 'from_html' => 'true/false' (so we know whether to stripslashes or not)
+ * 'html' => '0/1',
+ * 'from_name' => '',
+ * 'from_email' => '',
+ * 'priority' => '0/1',
+ * 'to_email' => 'email@email.com',
+ * 'to_name' => '',
+ * 'bcc_list' => array('email@email.com'),
+ * 'cc_list' => array('email@email.com'),
+ * 'subject' => '',
+ * 'body_text' => '',
+ * 'body_html' => '',
+ * 'attachments' => array(array('file' => 'file.exe',
+ * 'data' => 'file data here...'))
+ * 'server' => 'mail.domain.com',
+ * 'account' => '',
+ * 'password' => '');
+ *
+ *
+ * @package AgileBill
+ * @subpackage Core
*/
-class CORE_email
-{
+class CORE_email {
var $debug=false;
- function PHP_Mail($arr)
- {
- ### SET THE SMTP SETTINGS
- #ini_set('sendmail_from', @$arr['from_email']);
- #ini_set('SMTP', @$arr['server']);
+ public function PHP_Mail($arr) {
+ # SET THE SMTP SETTINGS
+ #ini_set('sendmail_from',@$arr['from_email']);
+ #ini_set('SMTP',@$arr['server']);
- ### CC LIST
- if(isset($arr['cc_list']) == 'array')
- {
- if(count($arr['cc_list'] > 0))
- {
- $cc = '';
- for($i=0; $i',$arr['from_name'],$arr['from_email'])."\r\n";
+ $headers .= sprintf('Reply-To: "%s" <%s>',$arr['from_name'],$arr['from_email'])."\r\n";
+
+ # HTML/non-HTML version of body & headers
+ $headers .= "MIME-Version: 1.0\r\n";
+ if (isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html'])) {
+ # Specify MIME version 1.0
+ $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
+ $body = $arr['body_html'];
+
+ } else {
+ # Specify MIME version 1.0
+ $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
+ $body = $arr['body_text'];
}
- ### BCC LIST
- if(isset($arr['bcc_list']) == 'array')
- {
- if(count($arr['bcc_list'] > 0))
- {
- $bcc = '';
- for($i=0; $i\r \n";
- $headers .= "Reply-To: \"".$arr['from_name']."\" <".$arr['from_email'].">\r \n";
-
- # html/non-html version of body & headers
- if(isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html']))
- {
- ### specify MIME version 1.0
- $headers .= "MIME-Version: 1.0\r \n";
- $headers .= "Content-type: text/html; charset=iso-8859-1\r \n";
- $body = $arr['body_html'];
- }
- else
- {
- ### specify MIME version 1.0
- $headers .= "MIME-Version: 1.0\r \n";
- $headers .= "Content-type: text/plain; charset=iso-8859-1\r \n";
- $body = $arr['body_text'];
- }
-
-
- ### CC:
- if(isset($cc))
- $headers .= "Cc: ".$cc."\r \n";
-
- ### BCC:
- if(isset($bcc))
- $headers .= "Bcc: ".$bcc."\r \n";
+ # BCC:
+ if (trim($bcc))
+ $headers .= sprintf('Bcc: %s',$bcc)."\r\n";
### PRIORITY
if(isset($arr['priority']) && $arr['priority'] == '1')
- $headers .= "X-Priority: 1";
+ $headers .= "X-Priority: 1\r\n";
else
- $headers .= "X-Priority: 3";
+ $headers .= "X-Priority: 3\r\n";
-
- /*
- echo "";
- echo print_r($arr);
- echo $headers;
- echo $body;
- */
-
- ### Strip Slashes
- if (!isset($arr['from_html']) || @$arr['html_form'] == false) {
- # from database, we must strip slashes
+ # Strip Slashes
+ if (! isset($arr['from_html']) || @$arr['html_form'] == false) {
+ # From database, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
- $body = stripslashes($body);
+ $body = stripslashes($body);
+
} elseif (@$arr['from_html'] == true && get_magic_quotes_gpc()) {
- # straight from html, we must strip slashes
+ # Straight from html, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
- $body = stripslashes($body);
+ $body = stripslashes($body);
}
- if($this->debug)
- {
- if(mail($arr['to_email'], $arr['subject'], $body, $headers)) {
+ if ($this->debug) {
+ if (mail($arr['to_email'],$arr['subject'],$body,$headers)) {
global $C_debug;
- $message = 'PHP mail() failed to send message "'.$arr['subject'].'" to "'.$arr['to_email'].'"';
- $C_debug->alert('CORE:email.inc.php','SMTP_Mail', $message);
- return false;
- }
- }
- else
- {
- if(@mail($arr['to_email'], $arr['subject'], $body, $headers)) {
- global $C_debug;
- $message = 'PHP mail() failed to send message "'.$arr['subject'].'" to "'.$arr['to_email'].'"';
+ $C_debug->alert(__FILE__,__METHOD__,sprintf('PHP mail() failed to send message "%s" to "%s"',$arr['subject'],$arr['to_email']));
+
+ return false;
+ }
+
+ } else {
+ if (@mail($arr['to_email'],$arr['subject'],$body,$headers)) {
+ global $C_debug;
+ $C_debug->alert(__FILE__,__METHOD__,sprintf('PHP mail() failed to send message "%s" to "%s"',$arr['subject'],$arr['to_email']));
+
return false;
}
}
+
return true;
}
-
-
- function SMTP_Mail($arr)
- {
- ### include the phpmailer class
- require_once(PATH_INCLUDES."phpmailer/class.phpmailer.php");
+ public function SMTP_Mail($arr) {
+ # Include the phpmailer class
+ require_once(PATH_INCLUDES.'phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
+
$mail->IsSMTP();
- $mail->SMTPAuth = true;
- $mail->Host = @$arr['server'];
- $mail->Username = @$arr['account'];
- $mail->Password = @$arr['password'];
- $mail->From = $arr['from_email'];
- $mail->FromName = $arr['from_name'];
- $mail->AddAddress($arr['to_email'], @$arr['to_name']);
+ $mail->SMTPAuth = true;
+ $mail->Host = @$arr['server'];
+ $mail->Username = @$arr['account'];
+ $mail->Password = @$arr['password'];
+ $mail->From = $arr['from_email'];
+ $mail->FromName = $arr['from_name'];
+ $mail->AddAddress($arr['to_email'],@$arr['to_name']);
#$mail->AddReplyTo($arr['from_name'], $arr['from_email']);
+ # CC LIST
+ if (isset($arr['cc_list']) && is_array($arr['cc_list']))
+ foreach ($arr['cc_list'] as $email)
+ $mail->AddCC($email,'');
- ### CC LIST
- if(is_array(@$arr['cc_list']))
- for($i=0; $iAddCC($arr['cc_list'][$i], "");
+ # BCC LIST
+ if (isset($arr['bcc_list']) && is_array($arr['bcc_list']))
+ foreach ($arr['bcc_list'] as $email)
+ $mail->AddBCC($email,'');
- ### BCC LIST
- if(is_array(@$arr['bcc_list']))
- for($i=0; $iAddBCC($arr['bcc_list'][$i], "");
-
- ### Strip Slashes
- if (empty($arr['from_html']) || @$arr['html_form'] == false) {
- # from database, we must strip slashes
- $arr['subject'] = stripslashes($arr['subject']);
+ # Strip Slashes
+ if (! isset($arr['from_html']) || @$arr['html_form'] == false) {
+ # From database, we must strip slashes
+ $arr['subject'] = stripslashes($arr['subject']);
@$arr['body_html'] = stripslashes($arr['body_html']);
@$arr['body_text'] = stripslashes($arr['body_text']);
+
} elseif (@$arr['from_html'] == true && get_magic_quotes_gpc()) {
- # straight from html, we must strip slashes
+ # Straight from html, we must strip slashes
$arr['subject'] = stripslashes($arr['subject']);
@$arr['body_html'] = stripslashes($arr['body_html']);
@$arr['body_text'] = stripslashes($arr['body_text']);
}
- # html/non-html version of body & headers
- if(isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html'])) {
+ # HTML/non-HTML version of body & headers
+ if (isset($arr['html']) && $arr['html'] == '1' && isset($arr['body_html'])) {
$mail->IsHTML(true);
- $mail->Body = @$arr['body_html'];
- $mail->AltBody = @$arr['body_text'];
- } else {
+ $mail->Body = @$arr['body_html'];
+ $mail->AltBody = @$arr['body_text'];
+
+ } else {
$mail->IsHTML(false);
- $mail->Body = @$arr['body_text'];
+ $mail->Body = @$arr['body_text'];
$mail->WordWrap = 50;
}
- # subject
- $mail->Subject = $arr['subject'];
+ # Subject
+ $mail->Subject = $arr['subject'];
# PRIORITY
if(isset($arr['priority']) && $arr['priority'] == '1')
- $mail->Priority = 1;
+ $mail->Priority = 1;
else
- $mail->Priority = 3;
+ $mail->Priority = 3;
-
- /* attachments
+ /* Attachments
$mail->AddAttachment("/var/tmp/file.tar.gz");
$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
*/
- if(!$mail->Send())
- {
- if($this->debug) {
- global $C_debug;
- $message = 'SMTP mail() failed to send message "'.$arr['subject'].'" to "'.$arr['to_email'].'" on server "'.$arr['server'].'"';
- $C_debug->error('CORE:email.inc.php','SMTP_Mail', $message . ' ---- '.$mail->ErrorInfo);
- echo "Message was not sent ";
- echo "Mailer Error: " . $mail->ErrorInfo;
- } else {
- global $C_debug;
- $message = 'SMTP mail() failed to send message "'.$arr['subject'].'" to "'.$arr['to_email'].'" on server "'.$arr['server'].'"';
- $C_debug->error('CORE:email.inc.php','SMTP_Mail', $message. ' ---- '.$mail->ErrorInfo);
+ if (! $mail->Send()) {
+ global $C_debug;
+ $C_debug->error(__FILE__,__METHOD__,sprintf('SMTP mail() failed to send message "%s" to "%s" on server "%s" (%s)',
+ $arr['subject'],$arr['to_email'],$arr['server'],$mail->ErrorInfo));
+
+ if ($this->debug) {
+ echo 'Message was not sent
';
+ printf('Mailer Error: %s',$mail->ErrorInfo);
}
- return false;
+
+ return false;
}
+
return true;
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/list.inc.php b/modules/core/list.inc.php
index db0db994..8a9c104c 100644
--- a/modules/core/list.inc.php
+++ b/modules/core/list.inc.php
@@ -1,58 +1,102 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core
*/
-
-class CORE_list
-{
- var $id;
- function menu($input_id, $name, $table, $field, $id, $class, $all=false) {
+/**
+ * The main AgileBill CORE List Class
+ *
+ * @package AgileBill
+ * @subpackage Core
+ */
+class CORE_list {
+ private $id = 100;
+
+ /**
+ * @todo deprecite this function - replace with mmenu()
+ */
+ public function menu($input_id,$name,$table,$field,$default,$class,$all=false) {
+ $this->mmenu($input_id,$name,$table,$field,$default,'',$class,$all);
+ }
+
+ /**
+ * Generate a select list, using the values in a table
+ *
+ * @param string $input_id HTML id="" value.
+ * + If 'no', then a hot click img wont be included
+ * + If 'all', then a blank item will be included
+ * @param string $name HTML name="" value.
+ * @param string $table Table to query for a list of items.
+ * @param string $field Column to query for a list of items.
+ * @param string $default Default Value to pre-select (if it exists)
+ * + If 'all', then a blank item will be included
+ * @param string|array $where SQL where conditions
+ * @param string $class CSS class for the select list
+ * @param bool $all If true, then a blank item will be included.
+ *
+ * @todo Remove the many ways of selecting all
+ */
+ public function mmenu($input_id,$name,$table,$field,$default,$where,$class,$all=false) {
global $C_translate;
- if($all == true || $id == 'all') $all = true;
- if(!isset($this->id)) $this->id = 100;
- if($input_id <= 0 && $input_id != 'no') $input_id = $this->id++;
+
+ $noicon = false;
+
+ if ($input_id == 'no') {
+ $input_id = '';
+ $noicon = true;
+ }
+
+ if (! $input_id)
+ $input_id = sprintf('%s_%s_%s',$table,$field,$this->id++);
+
$db = &DB();
- $sql= "SELECT id, $field FROM ".AGILE_DB_PREFIX."$table WHERE site_id = '" . DEFAULT_SITE . "' ORDER BY $field";
- $result = $db->Execute($sql);
- if ($result === false)
- {
+ $result = $db->Execute(sqlSelect($db,$table,sprintf('id,%s',$field),$where,$field));
+ if ($result === false) {
global $C_debug;
- $C_debug->error('list.inc.php','menu', $db->ErrorMsg());
+
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+
} else {
- $return = '';
- if($all)
- $return .= ' ';
+ $return = sprintf('',$input_id,$name,$class);
+
+ if ($all)
+ $return .= ' ';
+
$i = 0;
- while (!$result->EOF) {
- $return .= 'fields["id"])
- $return .= "selected";
- $return .= '>' . $result->fields["$field"] . '
- ';
- $i++;
+ while (! $result->EOF) {
+ $return .= sprintf('%s ',$result->fields['id'],($default == $result->fields['id']) ? ' selected="selected"' : '',$result->fields[$field]);
$result->MoveNext();
+
+ $i++;
}
- if($i==0)
- $return .= ''. $C_translate->translate('lists_none_defined','CORE','').' ';
+
$return .= ' ';
- if($i > 0 && $input_id != 'no')
- $return .= ' ';
+
+ if ($i==0)
+ $return = $C_translate->translate('lists_none_defined');
+
+ if ($i > 0 && ! $noicon)
+ $return .= sprintf(' ',THEME_NAME,$table,$input_id);
+
echo $return;
}
}
@@ -66,25 +110,190 @@ class CORE_list
include_once(PATH_MODULES . 'account_billing/account_billing.inc.php');
$acct_bill = new account_billing;
echo $acct_bill->menu_admin($field, $account, $default, $class, $user);
- }
+ }
function menu_multi($default, $name, $table, $field, $id, $max, $class) {
- include_once(PATH_CORE . 'list_menu_multi.inc.php');
- echo list_menu_multi($default, $name, $table, $field, $id, $max, $class);
+ include_once(PATH_CORE.'list_menu_multi.inc.php');
+ echo list_menu_multi($default, $name, $table, $field, $id, $max, $class);
}
function menu_files($id, $name, $default, $path, $pre, $ext, $class) {
- include_once(PATH_CORE . 'list_menu_files.inc.php');
+ include_once(PATH_CORE.'list_menu_files.inc.php');
echo list_menu_files($id, $name, $default, $path, $pre, $ext, $class);
}
+ /**
+ * Generate a list of frequently used selections in OSB
+ *
+ * @param string $type List type
+ * @param string $input_id HTML id="" value.
+ * @param string $name HTML name="" value.
+ * @param string $default Default Value to pre-select (if it exists)
+ * @param string $class CSS class for the select list
+ * @param bool $all If true, then a blank item will be included.
+ */
+ public function menu_staticlist($type,$input_id,$name,$default,$class,$all=false) {
+ global $C_list;
+
+ # Whether the values are also keys.
+ $nokeys = false;
+ $list = array();
+
+ switch ($type) {
+ case 'assoc_grant_type':
+ $list = array(0=>_('Grant access for specified amount of days'),1=>_('Grant access while associated subscription is active'),2=>_('Grant access forerver'));
+ break;
+
+ case 'assoc_prod_type':
+ $list = array(0=>_('Require All Selected Products'),1=>_('Require Any One Selected Product'));
+ break;
+
+ case 'charge_sweep':
+ $list = array(0=>_('Daily'),1=>_('Weekly'),2=>_('Monthly'),3=>_('Quarterly'),4=>_('Semi-Annually'),5=>_('Annually'),6=>_('Service Rebill'));
+ break;
+
+ case 'commissiontype':
+ $list = array(0=>_('None'),1=>_('Percentage Based'),2=>('Flat Rate'));
+ break;
+
+ # @todo To deprecate this and standardise with commissiontype
+ case 'discounttype':
+ $list = array(0=>_('Percentage Based'),1=>('Flat Rate'));
+ break;
+
+ case 'copluginmode':
+ $list = array(0=>_('Test'),1=>_('Live'));
+ break;
+
+ case 'domaintype':
+ $list = array(
+ 'register'=>_('Register'),
+ 'transfer'=>_('Transfer'),
+ 'park'=>_('Park')
+ );
+
+ break;
+
+ case 'email_piping':
+ $list = array(0=>' ',1=>'POP',2=>'IMAP');
+ break;
+
+ case 'email_piping_action':
+ $list = array(0=>_('Leave message in mailbox'),1=>_('Delete message from mailbox'));
+ break;
+
+ case 'invoice_delivery':
+ $list = array(0=>_('None'),1=>_('E-Mail'),2=>_('Print'));
+ break;
+
+ case 'invoice_show_itemized':
+ $list = array(0=>_('Overview Only'),1=>_('Full Detail'));
+ break;
+
+ case 'nametitle':
+ $list = array(_('Mr'),_('Ms'),_('Mrs'),_('Miss'),_('Dr'),_('Prof'));
+ $nokeys = true;
+ break;
+
+ case 'os':
+ $list = array(0=>'Linux',1=>'Windows');
+ break;
+
+ case 'recur_schedule':
+ $list = array(0=>_('Weekly'),1=>_('Monthly'),2=>_('Quarterly'),3=>_('Semi-Annually'),4=>_('Annually'),5=>_('Two years'),6=>_('Three Years'));
+ break;
+
+ case 'recur_type':
+ $list = array(0=>_('Bill on Aniversary Date of Subscription'),1=>_('Bill on Fixed Schedule'));
+ break;
+
+ case 'pricetype':
+ $list = array(0=>_('One-time Charge'),1=>_('Recurring Membership/Subscription'),2=>_('Trial for Membership/Subscription'));
+ break;
+
+ case 'servicetype':
+ if ($C_list->is_installed('host_server')) {
+ $list['host'] = _('Hosting');
+ $list['host_group'] = _('Hosting & Group Access');
+ $list['domain'] = _('Domain Name');
+ }
+ $list['none'] = _('Recurring Only');
+
+ break;
+
+ case 'servicequeue':
+ $list = array(
+ 'new'=>_('Add New'),
+ 'active'=>_('Activate'),
+ 'inactive'=>_('Deactivate'),
+ 'delete'=>_('Delete'),
+ 'edit'=>_('Edit/Update'),
+ 'queue_none'=>_('None')
+ );
+
+ break;
+
+ case 'statictype':
+ $list = array(
+ 'small_text'=>_('Small Text'),
+ 'medium_text'=>_('Medium Text'),
+ 'large_text'=>_('Large Text'),
+ 'dropdown_list'=>_('Dropdown List'),
+ 'calendar'=>_('Calendar'),
+ 'file_upload'=>_('File Upload'),
+ 'status'=>_('Status'),
+ 'checkbox'=>_('Checkbox'),
+ 'hidden'=>_('Hidden')
+ );
+ break;
+
+ case 'tasktype':
+ $list = array(0=>_('Internal Method'),1=>_('System Call'));
+ break;
+
+ case 'trial_length':
+ $list = array(0=>_('Days'),1=>_('Weeks'),2=>_('Months'));
+ break;
+
+ default: return sprintf('Unknown staticlist: %s',$type);
+ }
+
+ # If id is blank, we'll just return the value
+ if (! $input_id)
+ return $list[$default];
+
+ $return = sprintf('',$input_id,$name,$class);
+
+ if ($all)
+ $return .= ' ';
+
+ foreach ($list as $element => $details) {
+ $selected = '';
+
+ if ($nokeys) {
+ if ($default == $details)
+ $selected = ' selected="selected"';
+
+ } else {
+ if ($default == $element)
+ $selected = ' selected="selected"';
+ }
+
+ $return .= sprintf('%s ',$nokeys ? $details : $element,$selected,$details);
+ }
+
+ $return .= ' ';
+
+ return $return;
+ }
+
function format_currency ($number, $currency_id) {
- if(empty($number)) $number = 0;
+ if(empty($number)) $number = 0;
if(empty($currency_id)) $currency_id = DEFAULT_CURRENCY;
if(!isset($this->format_currency[$currency_id])) $this->currency($currency_id);
if($currency_id != DEFAULT_CURRENCY)
- if(!isset($this->format_currency[DEFAULT_CURRENCY]))
- $this->currency(DEFAULT_CURRENCY);
+ if(!isset($this->format_currency[DEFAULT_CURRENCY]))
+ $this->currency(DEFAULT_CURRENCY);
$number *= $this->format_currency[DEFAULT_CURRENCY]["convert"][$currency_id]["rate"];
if($number > .05 || $number == 0 || $number < -1)
return $this->format_currency[$currency_id]["symbol"]
@@ -93,33 +302,33 @@ class CORE_list
else
return $this->format_currency[$currency_id]["symbol"]
. "" . number_format($number, 3) . " "
- . $this->format_currency[$currency_id]["iso"];
+ . $this->format_currency[$currency_id]["iso"];
}
function format_currency_num ($number, $currency_id) {
- if(empty($number)) $number = 0;
+ if(empty($number)) $number = 0;
if(empty($currency_id)) $currency_id = DEFAULT_CURRENCY;
if(!isset($this->format_currency[$currency_id])) $this->currency($currency_id);
- if(!isset($this->format_currency[DEFAULT_CURRENCY])) $this->currency(DEFAULT_CURRENCY);
+ if(!isset($this->format_currency[DEFAULT_CURRENCY])) $this->currency(DEFAULT_CURRENCY);
$number *= $this->format_currency[DEFAULT_CURRENCY]["convert"][$currency_id]["rate"];
if($number > .05 || $number == 0 || $number < -1)
return $this->format_currency[$currency_id]["symbol"] . number_format($number, DEFAULT_DECIMAL_PLACE);
else
- return $this->format_currency[$currency_id]["symbol"] . number_format($number, 3);
- }
+ return $this->format_currency[$currency_id]["symbol"] . number_format($number, 2);
+ }
function format_currency_decimal ($number, $currency_id) {
if(empty($number)) return 0;
if(empty($currency_id)) $currency_id = DEFAULT_CURRENCY;
if(!isset($this->format_currency[$currency_id])) $this->currency($currency_id);
- if(!isset($this->format_currency[DEFAULT_CURRENCY])) $this->currency(DEFAULT_CURRENCY);
+ if(!isset($this->format_currency[DEFAULT_CURRENCY])) $this->currency(DEFAULT_CURRENCY);
return round($number *= $this->format_currency[DEFAULT_CURRENCY]["convert"][$currency_id]["rate"], 2);
- }
+ }
function currency_list($ret) {
if(!isset($this->format_currency[$currency_id])) $this->currency(DEFAULT_CURRENCY);
global $smarty;
- $smarty->assign("$ret", $this->format_currency[DEFAULT_CURRENCY]["convert"]);
+ $smarty->assign("$ret", $this->format_currency[DEFAULT_CURRENCY]["convert"]);
}
function currency_iso ($currency_id) {
@@ -147,13 +356,13 @@ class CORE_list
function radio($input_id, $name, $table, $field, $id, $class) {
include_once(PATH_CORE . 'list_radio.inc.php');
- echo list_radio($input_id, $name, $table, $field, $id, $class);
- }
+ echo list_radio($input_id, $name, $table, $field, $id, $class);
+ }
function check($input_id, $name, $table, $field, $default, $class) {
include_once(PATH_CORE . 'list_check.inc.php');
echo list_check($input_id, $name, $table, $field, $default, $class);
- }
+ }
function select_groups($default, $field_name, $class, $size, $own_account) {
include_once(PATH_CORE . 'list_select_groups.inc.php');
@@ -161,46 +370,52 @@ class CORE_list
}
function calender_view($field, $default, $css, $id) {
- if(isset($default) && $default != '' && $default != '0')
+ if(isset($default) && $default != '' && $default != '0')
$default = date(UNIX_DATE_FORMAT, $default);
else
$default = '';
include_once(PATH_CORE.'list_calendar.inc.php');
- echo list_calender_add($field, $default, $css);
- }
-
- function calender_add($field, $default, $css) {
- if($default == 'now') $default = date(UNIX_DATE_FORMAT, time());
- include_once(PATH_CORE.'list_calendar.inc.php');
- echo list_calender_add($field, $default, $css);
+ echo list_calender_add($field, $default, $css,$id);
}
+ public function calender_add($field,$default,$css,$id='') {
+ if ($default == 'now')
+ $default = date(UNIX_DATE_FORMAT,time());
+
+ include_once(PATH_CORE.'list_calendar.inc.php');
+ echo list_calender_add($field,$default,$css,$id);
+ }
+
+ # @todo Remove?
function calender_add_static_var($field, $default, $css) {
if($default == 'now') $default = date(UNIX_DATE_FORMAT, time());
include_once(PATH_CORE.'list_calendar.inc.php');
echo list_calender_add_static($field, $default, $css);
}
- function calender_search($field, $default, $css) {
- if($default == 'now') $default = date(UNIX_DATE_FORMAT, time());
+ function calender_search($field, $default, $css) {
+ if ($default == 'now')
+ $default = date(UNIX_DATE_FORMAT, time());
+
echo '
>
- >
- <=
- >=
- !=
- ';
- $this->calender_view($field.'[0]', $default, $css, 1);
- echo '
-
<
- <
<=
>=
!=
';
- $this->calender_view($field.'[1]', $default, $css, 1);
+
+ $this->calender_view($field,$default,$css,0);
+ echo '
+
+ <
+ >
+ <=
+ >=
+ !=
+ ';
+ $this->calender_view($field,$default,$css,1);
}
function setup_default_date($default, $css) {
@@ -208,19 +423,20 @@ class CORE_list
echo list_setup_default_date($default, $css);
}
- function card_type_menu($default_selected, $checkout_id, $field='checkout_plugin_data[card_type]', $class) {
+ function card_type_menu($default_selected, $checkout_id, $field='checkout_plugin_data[card_type]', $class,$all=false) {
include_once(PATH_CORE . 'list_card_type_menu.inc.php');
- echo list_card_type_menu($default_selected, $checkout_id, $field, $class);
- }
+ echo list_card_type_menu($default_selected, $checkout_id, $field, $class,$all);
+ }
- function date($date) {
+ function date($date) {
if($date == '') $date = time();
- return date(UNIX_DATE_FORMAT, $date);
- }
+ return date(UNIX_DATE_FORMAT, $date);
+ }
- function date_time($date) {
- if($date == '') $date = time();
- $ret = date(UNIX_DATE_FORMAT, $date);
+ function date_time($date) {
+ if ($date == '')
+ return 'UNKNOWN';
+ $ret = date(UNIX_DATE_FORMAT, $date);
$ret .= " ".date(DEFAULT_TIME_FORMAT, $date);
return $ret;
}
@@ -228,7 +444,7 @@ class CORE_list
function unserial ($data, $var) {
global $smarty;
if(is_string($data)) $array = unserialize($data);
- if(is_array($array)) $smarty->assign($var, $array);
+ if(is_array($array)) $smarty->assign($var, $array);
return;
}
@@ -237,18 +453,18 @@ class CORE_list
$sql= "SELECT id, $field FROM ".AGILE_DB_PREFIX."$table
WHERE site_id = '" . DEFAULT_SITE . "'" . $sql . "
ORDER BY $field";
- $result = $db->Execute($sql);
+ $result = $db->Execute($sql);
if ($result === false)
{
global $C_debug;
- $C_debug->error('list.inc.php','smarty_array', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return false;
- }
+ }
while (!$result->EOF)
- {
+ {
$smart[] = $result->fields;
$result->MoveNext();
- }
+ }
global $smarty;
$smarty->assign("$return", $smart);
return true;
@@ -261,11 +477,11 @@ class CORE_list
WHERE site_id = " . $db->qstr(DEFAULT_SITE) . " AND
language_id = " . $db->qstr(SESS_LANGUAGE). " AND " .
$field2 . " = " . $db->qstr($id);
- $result = $db->Execute($sql);
+ $result = $db->Execute($sql);
if ($result === false)
{
global $C_debug;
- $C_debug->error('list.inc.php','translate', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return false;
} else if($result->RecordCount() > 0) {
$smarty->assign("$var", $result->fields);
@@ -278,10 +494,10 @@ class CORE_list
WHERE site_id = " . $db->qstr(DEFAULT_SITE) . " AND
language_id = " . $db->qstr(DEFAULT_LANGUAGE). " AND " .
$field2 . " = " . $db->qstr($id);
- $result = $db->Execute($sql);
+ $result = $db->Execute($sql);
if ($result === false) {
global $C_debug;
- $C_debug->error('list.inc.php','translate', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
return false;
} else if($result->RecordCount() > 0) {
$smarty->assign("$var", $result->fields);
@@ -293,29 +509,39 @@ class CORE_list
}
}
- function bool($field, $curr_value, $extra) {
+ public function bool($field,$curr_value,$class='form_menu',$extra='') {
global $C_translate;
- if($curr_value == 'all') {
+
+ # If the field is blank, we'll just return true/false
+ if (! $field)
+ return $curr_value ? $C_translate->translate('true') : $C_translate->translate('false');
+
+ if ($curr_value == 'all') {
$true = '';
$false= '';
- } else if($curr_value == "1") {
- $true = ' selected';
+
+ } elseif($curr_value == '1') {
+ $true = ' selected="selected"';
$false= '';
+
} else {
$true = '';
- $false= ' selected';
+ $false= ' selected="selected"';
}
- $return = '';
- if($curr_value == 'all')
- $return .= '
- ';
- $return .= ''. $C_translate->translate('true', 'CORE','') . ' ';
- $return .= ''. $C_translate->translate('false','CORE','') . ' ';
- $return .= ' ';
+ $return = sprintf('',$field,$field,$class,$extra);
+
+ if ($curr_value == 'all')
+ $return .= ' ';
+
+ $return .= sprintf('%s ',$true,$C_translate->translate('true'));
+ $return .= sprintf('%s ',$false,$C_translate->translate('false'));
+ $return .= ' ';
+
echo $return;
}
+ // @todo this looks the same as bool()
function bool_static_var($field, $curr_value, $class) {
global $C_translate;
if ($curr_value == 'all') {
@@ -328,12 +554,12 @@ class CORE_list
$true = ' selected';
$false= '';
}
- $return = '';
+ $return = '';
if($curr_value == 'all')
- $return .= ' ';
+ $return .= ' ';
$return .= ''. $C_translate->translate('true', 'CORE','') . ' ';
$return .= ''. $C_translate->translate('false','CORE','') . ' ';
- $return .= ' ';
+ $return .= ' ';
return $return;
}
@@ -372,7 +598,9 @@ class CORE_list
$graph->PIE_graph($module, $method, $range, $start, $extra);
}
- function is_installed($module) {
+ # @todo consider changing this so that it returns the .inc file if the module is installed
+ # so that $a = x->is_installed('y'); require_once $a can be used
+ function is_installed($module) {
if(@$this->is_installed[$module] == true) return true;
if($this->auth_method_by_name($module, 'search')) {
$this->is_installed[$module] = true;
@@ -393,15 +621,22 @@ class CORE_list
}
function auth_method_by_name($module, $method) {
- global $C_auth;
- if(!is_object($C_auth)) return false;
- return $C_auth->auth_method_by_name($module, $method);
+ global $C_auth;
+
+ if (!is_object($C_auth))
+ return false;
+
+ return $C_auth->auth_method_by_name($module,$method);
}
- function generate_admin_menu() {
+ /**
+ * Generate the admin menu
+ */
+ public function generate_admin_menu() {
global $C_auth;
+
echo $C_auth->generate_admin_menu();
- }
+ }
function account($field) {
if (empty($this->account) && SESS_LOGGED) {
@@ -413,11 +648,11 @@ class CORE_list
$this->account = $result->fields;
}
echo $this->account[$field];
- }
+ }
# Get the AgileBill version info
function version() {
require_once(PATH_CORE.'version.inc.php');
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/list_calendar.inc.php b/modules/core/list_calendar.inc.php
index 9eb60bd9..d835516e 100644
--- a/modules/core/list_calendar.inc.php
+++ b/modules/core/list_calendar.inc.php
@@ -1,60 +1,66 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Template:Calendar
*/
-
-function list_calender_add($field, $default, $css)
-{
- # set the date to current date if 'now' is set as $default
- if($default == 'now')
- {
- $default = date(UNIX_DATE_FORMAT, time());
- }
+
+/**
+ * The main AgileBill Template Calendar Method
+ *
+ * @package AgileBill
+ * @subpackage Template:Calendar
+ */
+
+function list_calender_add($field,$default,$css,$fid) {
+ # Set the date to current date if 'now' is set as $default
+ if ($default == 'now')
+ $default = date(UNIX_DATE_FORMAT,time());
$id = rand(9,999);
- $ret = '
-
-
-
- ';
+ $ret = '';
+ if ($fid)
+ $ret .= sprintf(' ',$field,$fid,$id,$field,$fid,$css,$default);
+ else
+ $ret .= sprintf(' ',$field,$fid,$id,$field,$css,$default);
+ $ret .= sprintf(' ',$field,$fid,$id);
+ $ret .= '';
+
return $ret;
-}
+}
+# @todo Remove?
+function list_calender_add_static($field,$default,$css) {
+ return list_calender_add($field,$default,$css,'');
-function list_calender_add_static($field, $default, $css)
-{
- # set the date to current date if 'now' is set as $default
- if($default == 'now')
- {
- $default = date(UNIX_DATE_FORMAT);
- }
+ # Set the date to current date if 'now' is set as $default
+ if ($default == 'now')
+ $default = date(UNIX_DATE_FORMAT);
$id = rand(9,999);
$ret = '
-
+
";
@@ -410,28 +379,23 @@ class CORE_search
{
$this->recent_js = FALSE;
}
- } # end of functino
-
-
-
+ } # End of functino
/**
- * Build the saved search menu and JavaScript
- *
- * @return void
- * @since Version 1.0
- * @param string Contains the name of the Module to find saved searches for
- */
-
- function build_saved($module)
- {
- # disable for now
+ * Build the saved search menu and JavaScript
+ *
+ * @param string Contains the name of the Module to find saved searches for
+ * @return void
+ * @since Version 1.0
+ */
+ function build_saved($module) {
+ # Disable for now
return 0;
if(isset($this->arr)) unset ($this->arr);
- # get the saved searches
- # get the recent searches
+ # Get the saved searches
+ # Get the recent searches
$db1 = &DB();
$q = "SELECT id, search_id, name
FROM " . AGILE_DB_PREFIX . "search_saved
@@ -446,17 +410,17 @@ class CORE_search
ORDER BY name ASC";
$result1 = $db1->Execute($q);
- # error reporting
+ # Error reporting
if ($result1 === false)
{
global $C_debug;
$C_debug->sql_error($db1->ErrorMsg());
}
- $i=0;
- while (!$result1->EOF)
- {
- # get the information for this search
+ $i=0;
+ while (!$result1->EOF)
+ {
+ # Get the information for this search
$db = &DB();
$q = "SELECT id, full_sql, order_by, limit_no
FROM " . AGILE_DB_PREFIX . "search
@@ -466,28 +430,28 @@ class CORE_search
site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
- # error reporting
+ # Error reporting
if ($result === false)
{
global $C_debug;
- $C_debug->error('search.inc.php','build_saved', $db->ErrorMsg());
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
- # get the fields for this loop
+ # Get the fields for this loop
$sql = $result->fields['full_sql'];
- # remove the WHERE
+ # Remove the WHERE
$sql = trim($sql);
$sql = eregi_replace("WHERE","",$sql);
$sql = eregi_replace("AND$","",$sql);
$sql = trim($sql);
- # replace any sql statements before we split the string
+ # Replace any sql statements before we split the string
$sql = ereg_replace(" = ","===",$sql);
$sql = ereg_replace(" LIKE ","===",$sql);
- # determine the number of fields
+ # Determine the number of fields
$ii=0;
if(ereg(" AND ", $sql))
@@ -495,16 +459,16 @@ class CORE_search
$sql = explode(" AND ",$sql);
$this_fields = count($sql);
- # loop
+ # Loop
for($count=0; $count < $this_fields; $count++)
{
- # do each field
+ # Do each field
$sqls = explode("==",$sql[$count]);
$field[$count][name] = $sqls[0];
$field[$count][value] = ereg_replace("'","",$sqls[1]);
$field[$count][value] = ereg_replace("=","",$field[$count][value]);
- # check that the name & value are both set...
+ # Check that the name & value are both set...
if($field[$count][value] != '' && $field[$count][name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -526,16 +490,16 @@ class CORE_search
}
else
{
- # field count
+ # Field count
$this_fields = 1;
- # do this one field
+ # Do this one field
$sqls = explode("==",$sql);
$field[name] = $sqls[0];
$field[value] = ereg_replace("'","",$sqls[1]);
$field[value] = ereg_replace("=","",$field[value]);
- # check that the name & value are both set...
+ # Check that the name & value are both set...
if($field[value] != '' && $field[name] != '')
{
if(!isset($this->arr[$i][$ii][limit]))
@@ -551,25 +515,25 @@ class CORE_search
# echo " Field/Name: " . $field[name] . " -> " . $field[value];
$ii++;
- # set the menu up for Smarty
+ # Set the menu up for Smarty
$this->saved_menu[$i] = $result->fields;
$this->saved_menu[$i]["name"] = $result1->fields["name"];
}
}
- $result1->MoveNext();
- if ($ii > 0) $i++;
+ $result1->MoveNext();
+ if ($ii > 0) $i++;
}
- # finish the JS:
+ # Finish the JS:
if($i > 0 && $ii > 0)
{
- # build the JavaScript
+ # Build the JavaScript
$this->saved_js = '
-
";
@@ -650,4 +614,4 @@ class CORE_search
}
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/service_group.inc.php b/modules/core/service_group.inc.php
index 5e78700d..b6a46e39 100644
--- a/modules/core/service_group.inc.php
+++ b/modules/core/service_group.inc.php
@@ -255,14 +255,6 @@ class service_group
include_once(PATH_CORE . 'list.inc.php');
$C_list = new CORE_list;
}
-
- if($C_list->is_installed('db_mapping'))
- {
- # Update the db_mapping accounts
- include_once ( PATH_MODULES . 'db_mapping/db_mapping.inc.php' );
- $db_map = new db_mapping;
- $db_map->account_group_sync ( $this->rs['account_id'] );
- }
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/session.inc.php b/modules/core/session.inc.php
index fe6011a9..2272d65f 100644
--- a/modules/core/session.inc.php
+++ b/modules/core/session.inc.php
@@ -325,7 +325,6 @@ class CORE_session
theme_id = ".$db->qstr($this->sess_theme_id).",
campaign_id = ".$db->qstr($this->sess_campaign_id);
$result = $db->Execute($q);
- $C_debug->sql_count();
if ($result === false) {
$C_debug->error('session.inc.php','validate', $db->ErrorMsg());
echo 'Unable to start session: Db error ' . $q . ' ' . $db->ErrorMsg();
@@ -370,7 +369,6 @@ class CORE_session
$db = &DB();
$q = "DELETE FROM " . AGILE_DB_PREFIX . "session WHERE id = '$sess' AND site_id = '" . DEFAULT_SITE . "'";
$result = $db->Execute($q);
- $C_debug->sql_count();
if ($result === false) $C_debug->error('session.inc.php','delete', $db->ErrorMsg());
}
@@ -397,7 +395,6 @@ class CORE_session
AND site_id = " . $db->qstr(DEFAULT_SITE);
$result = $db->Execute($q);
global $C_debug;
- $C_debug->sql_count();
if ($result === false) $C_debug->error('session.inc.php','session_constant', $db->ErrorMsg());
if(!defined("SESS_LOGGED"))
define ('SESS_LOGGED', $result->fields['logged']);
@@ -416,4 +413,4 @@ class CORE_session
define ('SESS_EXPIRES', 0);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/setup.inc.php b/modules/core/setup.inc.php
index 85614dab..b7c482e1 100644
--- a/modules/core/setup.inc.php
+++ b/modules/core/setup.inc.php
@@ -1,169 +1,169 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Core:Setup
*/
-
-class CORE_setup
-{
- function CORE_setup()
- {
- if(defined('MEMCACHE_ENABLED') && MEMCACHE_ENABLED == true) {
- require_once (PATH_INCLUDES. 'cache/cache.php');
+
+/**
+ * The main AgileBill Core Setup Class
+ *
+ * @package AgileBill
+ * @subpackage Core:Setup
+ */
+class CORE_setup {
+ public function __construct() {
+ if (defined('MEMCACHE_ENABLED') && MEMCACHE_ENABLED == true) {
+ require_once(PATH_INCLUDES.'cache/cache.php');
+
$key = md5('keyname1'.__FILE__.DEFAULT_SITE);
- $sec = 60*30;
+ $sec = 60*30;
$timeout = get_value($key.'_exp');
- if($timeout == "" || $timeout < time() || !$fields = get_value($key) )
- {
+ if ($timeout == '' || $timeout < time() || ! $fields = get_value($key)) {
$fields = $this->get_setup();
- store_value($key, $fields);
- store_value($key.'_exp', time()+$sec);
- }
+ store_value($key,$fields);
+ store_value($key.'_exp',time()+$sec);
+ }
+
} else {
$fields = $this->get_setup();
}
- define ('DEFAULT_COUNTRY', $fields['country_id']);
- define ('DEFAULT_LANGUAGE', $fields['language_id']);
- define ('DEFAULT_CURRENCY', $fields['currency_id']);
- define ('DEFAULT_WEIGHT', $fields['weight_id']);
- define ('DEFAULT_THEME', $fields['theme_id']);
- define ('DEFAULT_ADMIN_THEME', $fields['admin_theme_id']);
- define ('DEFAULT_GROUP', $fields['group_id']);
- define ('DEFAULT_AFFILIATE_TEMPLATE', $fields['affiliate_template_id']);
- define ('DEFAULT_AFFILIATE', $fields['affiliate_id']);
- define ('DEFAULT_RESELLER', $fields['reseller_id']);
- define ('DEFAULT_SETUP_EMAIL', $fields['setup_email_id']);
- define ('DEFAULT_TIME_FORMAT', $fields['time_format']);
- define ('DEFAULT_ACCOUNT_STATUS',$fields['default_account_status']);
+ define('DEFAULT_COUNTRY', $fields['country_id']);
+ define('DEFAULT_LANGUAGE', $fields['language_id']);
+ define('DEFAULT_CURRENCY', $fields['currency_id']);
+ define('DEFAULT_WEIGHT', $fields['weight_id']);
+ define('DEFAULT_THEME', $fields['theme_id']);
+ define('DEFAULT_ADMIN_THEME', $fields['admin_theme_id']);
+ define('DEFAULT_GROUP', $fields['group_id']);
+ define('DEFAULT_AFFILIATE_TEMPLATE', $fields['affiliate_template_id']);
+ define('DEFAULT_AFFILIATE', $fields['affiliate_id']);
+ define('DEFAULT_RESELLER', $fields['reseller_id']);
+ define('DEFAULT_SETUP_EMAIL', $fields['setup_email_id']);
+ define('DEFAULT_TIME_FORMAT', $fields['time_format']);
+ define('DEFAULT_ACCOUNT_STATUS',$fields['default_account_status']);
$this->default_date_format($fields['date_format']);
- if(!defined("DEFAULT_TIME_FORMAT"))
- define ('DEFAULT_TIME_FORMAT', $fields['time_format']);
- define ('DEFAULT_DATE_TIME_FORMAT', $fields['date_time_format']);
- define ('DEFAULT_DECIMAL_PLACE',$fields['decimal_place']);
- define ('COOKIE_NAME', $fields['cookie_name']);
- define ('COOKIE_EXPIRE', $fields['cookie_expire']);
- define ('SESSION_IP_MATCH', $fields['session_ip_match']);
- define ('SESSION_EXPIRE', $fields['login_expire']);
- define ('NEWSLETTER_REGISTRATION',$fields['newsletter_registration']);
- define ('SEARCH_EXPIRE', $fields['search_expire']);
- define ('ERROR_REPORTING', $fields['error_reporting']);
- define ('DEBUG', $fields['debug']);
+ if (! defined('DEFAULT_TIME_FORMAT'))
+ define('DEFAULT_TIME_FORMAT',$fields['time_format']);
+ define('DEFAULT_DATE_TIME_FORMAT',$fields['date_time_format']);
+ define('DEFAULT_DECIMAL_PLACE',$fields['decimal_place']);
+ define('COOKIE_NAME', $fields['cookie_name']);
+ define('COOKIE_EXPIRE', $fields['cookie_expire']);
+ define('SESSION_IP_MATCH', $fields['session_ip_match']);
+ define('SESSION_EXPIRE', $fields['login_expire']);
+ define('NEWSLETTER_REGISTRATION',$fields['newsletter_registration']);
+ define('SEARCH_EXPIRE', $fields['search_expire']);
+ define('ERROR_REPORTING', $fields['error_reporting']);
+ define('DEBUG', $fields['debug']);
- define ('LOGIN_ATTEMPT_TRY', $fields['login_attempt_try']);
- define ('LOGIN_ATTEMPT_TIME', $fields['login_attempt_time']);
- define ('LOGIN_ATTEMPT_LOCK', $fields['login_attempt_lock']);
- define ('DB_CACHE', $fields['db_cache']);
- define ('CACHE_SESSIONS', $fields['cache_sessions']);
- define ('WEBLOG', $fields['weblog']);
- define ('LICENSE_KEY', $fields['license_key']);
- define ('LICENSE_CODE', $fields['license_code']);
+ define('LOGIN_ATTEMPT_TRY', $fields['login_attempt_try']);
+ define('LOGIN_ATTEMPT_TIME', $fields['login_attempt_time']);
+ define('LOGIN_ATTEMPT_LOCK', $fields['login_attempt_lock']);
+ define('DB_CACHE', $fields['db_cache']);
+ define('CACHE_SESSIONS', $fields['cache_sessions']);
+ define('WEBLOG', $fields['weblog']);
- if(!defined('SSL_URL')) define ('SSL_URL', $fields['ssl_url']);
- if(!defined('URL')) define ('URL', $fields['nonssl_url']);
- if(!defined('SITE_NAME')) define ('SITE_NAME', $fields['site_name']);
- if(!defined('SITE_EMAIL')) define ('SITE_EMAIL', $fields['site_email']);
- if(!defined('SITE_ADDRESS'))define ('SITE_ADDRESS',$fields['site_address']);
- if(!defined('SITE_CITY')) define ('SITE_CITY', $fields['site_city']);
- if(!defined('SITE_STATE')) define ('SITE_STATE', $fields['site_state']);
- if(!defined('SITE_ZIP')) define ('SITE_ZIP', $fields['site_zip']);
- if(!defined('SITE_PHONE')) define ('SITE_PHONE', $fields['site_phone']);
- if(!defined('SITE_FAX')) define ('SITE_FAX', $fields['site_fax']);
+ if (! defined('SSL_URL')) define('SSL_URL', $fields['ssl_url']);
+ if (! defined('URL')) define('URL', $fields['nonssl_url']);
+ if (! defined('SITE_NAME')) define('SITE_NAME', $fields['site_name']);
+ if (! defined('SITE_EMAIL')) define('SITE_EMAIL', $fields['site_email']);
+ if (! defined('SITE_ADDRESS')) define('SITE_ADDRESS', $fields['site_address']);
+ if (! defined('SITE_CITY')) define('SITE_CITY', $fields['site_city']);
+ if (! defined('SITE_STATE')) define('SITE_STATE', $fields['site_state']);
+ if (! defined('SITE_ZIP')) define('SITE_ZIP', $fields['site_zip']);
+ if (! defined('SITE_PHONE')) define('SITE_PHONE', $fields['site_phone']);
+ if (! defined('SITE_FAX')) define('SITE_FAX', $fields['site_fax']);
- if($fields['os'] == 1)
- define ('AGILE_OS', 'WINDOWS');
+ if ($fields['os'] == 1)
+ define('AGILE_OS', 'WINDOWS');
else
- define ('AGILE_OS', 'LINUX');
+ define('AGILE_OS', 'LINUX');
- define ('PATH_CURL', $fields['path_curl']);
- define ('SHOW_AFFILIATE_LINK', $fields['show_affiliate_link']);
- define ('AUTO_AFFILIATE', @$fields['auto_affiliate']);
- define ('SHOW_TICKET_LINK', $fields['show_ticket_link']);
- define ('SHOW_NEWSLETTER_LINK', $fields['show_newsletter_link']);
- define ('SHOW_CONTACT_LINK', $fields['show_contact_link']);
- define ('SHOW_DOMAIN_LINK', $fields['show_domain_link']);
- define ('SHOW_CART_LINK', $fields['show_cart_link']);
- define ('SHOW_CHECKOUT_LINK', $fields['show_checkout_link']);
- define ('SHOW_PRODUCT_LINK', $fields['show_product_link']);
- define ('SHOW_CAT_BLOCK', $fields['show_cat_block']);
- define ('SHOW_FILE_BLOCK', $fields['show_file_block']);
- define ('SHOW_STATIC_BLOCK', $fields['show_static_block']);
- define ('SHOW_AFFILIATE_CODE', $fields['show_affiliate_code']);
- define ('SHOW_DISCOUNT_CODE', $fields['show_discount_code']);
- define ('BILLING_WEEKDAY', $fields['billing_weekday']);
- define ('GRACE_PERIOD', $fields['grace_period']);
- define ('MAX_BILLING_NOTICE', $fields['max_billing_notice']);
- define ('MAX_INV_GEN_PERIOD', $fields['max_inv_gen_period']);
+ define('PATH_CURL', $fields['path_curl']);
+ define('SHOW_AFFILIATE_LINK', $fields['show_affiliate_link']);
+ define('AUTO_AFFILIATE', @$fields['auto_affiliate']);
+ define('SHOW_NEWSLETTER_LINK', $fields['show_newsletter_link']);
+ define('SHOW_CONTACT_LINK', $fields['show_contact_link']);
+ define('SHOW_DOMAIN_LINK', $fields['show_domain_link']);
+ define('SHOW_CART_LINK', $fields['show_cart_link']);
+ define('SHOW_CHECKOUT_LINK', $fields['show_checkout_link']);
+ define('SHOW_PRODUCT_LINK', $fields['show_product_link']);
+ define('SHOW_CAT_BLOCK', $fields['show_cat_block']);
+ define('SHOW_STATIC_BLOCK', $fields['show_static_block']);
+ define('SHOW_AFFILIATE_CODE', $fields['show_affiliate_code']);
+ define('SHOW_DISCOUNT_CODE', $fields['show_discount_code']);
+ define('BILLING_WEEKDAY', $fields['billing_weekday']);
+ define('GRACE_PERIOD', $fields['grace_period']);
+ define('MAX_BILLING_NOTICE', $fields['max_billing_notice']);
- $error_reporting_eval = 'error_reporting('.ERROR_REPORTING.');';
- eval($error_reporting_eval);
+ error_reporting(ERROR_REPORTING);
}
- function get_setup()
- {
+ private function get_setup() {
$db = &DB();
- $q = "SELECT * FROM " . AGILE_DB_PREFIX . "setup WHERE site_id = ". DEFAULT_SITE;
- $result = $db->Execute($q);
- if ($result === false || @$result->RecordCount() == 0) {
- if(is_file('install/install.inc'))
+ $result = $db->Execute(sqlSelect($db,'setup','*',''));
+ if (! $result || $result->RecordCount() == 0) {
+ if (is_file('install/install.inc'))
require_once('install/install.inc');
else
$this->handle_failure($db);
exit;
+
} else {
return $result->fields;
}
- }
+ }
- function default_date_format($default)
- {
+ private function default_date_format($default) {
$default = unserialize($default);
$format = '';
$divider = $default[3];
- for($i=0; $i<3; $i++)
- {
+
+ for ($i=0; $i<3; $i++) {
$format .= $default[$i];
- if($i != 2)
- $format .= $divider;
+ if ($i != 2)
+ $format .= $divider;
}
+
$arr = Array('a','A','b','B','d','j','m','u','y','Y');
- for($i=0; $i_errorMsg));
- // log the error
- if($f=fopen(PATH_FILES.'sql_error.txt', 'a')) {
- $data = date("m-d-Y H:i:s a") . " " . $db->_errorMsg . "\r\n";
- fputs($f,$data);
- }
-
- exit;
+ exit;
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/core/sort_array.inc.php b/modules/core/sort_array.inc.php
index 35d0048c..eebc543a 100644
--- a/modules/core/sort_array.inc.php
+++ b/modules/core/sort_array.inc.php
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
+?>
diff --git a/modules/core/static_var.inc.php b/modules/core/static_var.inc.php
index 32f1c4d7..cbb91f58 100644
--- a/modules/core/static_var.inc.php
+++ b/modules/core/static_var.inc.php
@@ -166,12 +166,12 @@ class CORE_static_var
{
### SMALL TEXT FIELD
$this_html = ' ';
+ '" value="'.$static_value.'"/>';
}
elseif($display == 'search')
{
$this_html = ' ' .
+ '" value="'.$static_value.'"/>' .
$C_translate->translate('search_partial', 'CORE', SESS_LANGUAGE);
}
else
@@ -187,12 +187,12 @@ class CORE_static_var
{
### MEDIUM TEXT FIELD
$this_html = ' ';
+ '" value="'.$static_value.'"/>';
}
elseif($display == 'search')
{
$this_html = ' ' .
+ '" value="'.$static_value.'"/>' .
$C_translate->translate('search_partial', 'CORE', SESS_LANGUAGE);
}
else
@@ -213,7 +213,7 @@ class CORE_static_var
elseif($display == 'search')
{
$this_html = ' ' .
+ '" value="'.$static_value.'"/>' .
$C_translate->translate('search_partial', 'CORE', SESS_LANGUAGE);
}
else
@@ -289,7 +289,7 @@ class CORE_static_var
$id = rand(9,999);
$this_html = '
-
+
";
- }
-
- $C_debug->alert($message);
-}
-
-
-
-
- ############################################################################
- #>>>>> default Account Add module
- ############################################################################
-
- function MAP_account_add( $account_id, $MAP_this )
- {
- ### Get the local account details
- $db = &DB();
- $sql= 'SELECT * FROM '.AGILE_DB_PREFIX.'account WHERE
- site_id = '.$db->qstr(DEFAULT_SITE).' AND
- id = '.$db->qstr($account_id);
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_add', $db->ErrorMsg());
- return;
- }
-
- ### Create the insert statement
- $dbm = new db_mapping;
- $db = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "INSERT INTO " .
- $db_prefix . "" . $MAP_this->map['account_map_field'] . ' SET ';
-
- ### Define the main fields
- $comma=false;
- reset ( $MAP_this->map['account_fields'] );
- while ( list ($key, $val) = each ( $MAP_this->map['account_fields'] ))
- {
- if ( $val['map_field'] && $key != 'id')
- {
- if($comma) $sql .= " , ";
- $sql .= $val['map_field'] . " = ". $db->qstr($result->fields[$key]);
- $comma = true;
- }
- elseif ( $val['map_field'] && $key == 'id')
- {
- if(isset($val['unique']) && $val['unique'] == '1')
- {
- $remote_account_id = $db->GenID($db_prefix . "" . $MAP_this->map['account_map_field'] . '_id');
- if($comma) $sql .= " , ";
- $sql .= $val['map_field'] . " = ". $db->qstr($remote_account_id);
- $comma = true;
- }
- }
- }
-
- ### Define any custom fields
- for($i=0; $imap['extra_field']); $i++)
- {
- if ( $MAP_this->map['extra_field'][$i]['add'] )
- {
- if($comma) $sql .= " , ";
- $value = $MAP_this->map['extra_field'][$i]['value'];
-
- # conversion
- if ($value == 'random|64')
- $value = rand(999,99999) .''. md5(microtime() . '-' . rand(999,9999));
- if ($value == 'random|32')
- $value = md5(microtime() . rand(999,99999));
-
- $sql .= $MAP_this->map['extra_field'][$i]['name'] . " = ".$db->qstr($value);
- $comma = true;
- }
- }
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_add', $db->ErrorMsg());
- return;
- }
- return true;
- }
-
-
-
-
-
-
-
-
-
-
-
- ############################################################################
- #>>>>> default Account Edit method
- ############################################################################
-
- function MAP_account_edit($account_id, $old_username, $MAP_this)
- {
- $db = &DB();
- if( $old_username == '')
- {
- ### Get the username:
- $sql = 'SELECT username FROM ' . AGILE_DB_PREFIX . 'account WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($account_id);
- $result = $db->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_edit(1)', $db->ErrorMsg());
- return;
- }
-
- if($result->RecordCount() > 0)
- {
- $old_username = $result->fields['username'];
- }
- }
-
-
- if (@$old_username == strtolower('admin') ||
- @$old_username == strtolower('administrator'))
- return false;
-
- ### Get the current account details from the local db
- $sql= "SELECT * FROM " . AGILE_DB_PREFIX . "account WHERE
- id = " . $db->qstr($account_id) . " AND
- site_id = " . $db->qstr(DEFAULT_SITE);
- $result=$db->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_edit(2)', $db->ErrorMsg());
- return;
- }
-
- ### Create the sql update statement
- unset($db);
- $dbm = new db_mapping;
- $db = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "UPDATE " .
- $db_prefix . "" . $MAP_this->map['account_map_field'] . ' SET ';
-
-
- ### Define the main fields
- $comma=false;
- reset ( $MAP_this->map['account_fields'] );
- while ( list ($key, $val) = each ( $MAP_this->map['account_fields'] ))
- {
- if ( $val['map_field'] && $key != 'id')
- {
- if($comma) $sql .= " , ";
- $sql .= $val['map_field'] . " = ". $db->qstr($result->fields[$key]);
- $comma = true;
- }
- }
-
- ### Define any custom fields
- for($i=0; $imap['extra_field']); $i++)
- {
- if ( $MAP_this->map['extra_field'][$i]['edit'] )
- {
- if($comma) $sql .= " , ";
- $sql .= $MAP_this->map['extra_field'][$i]['name'] . " = ".
- $db->qstr($MAP_this->map['extra_field'][$i]['value']);
- $comma = true;
- }
- }
-
- ### Update the account in the remote db
- $sql .= " WHERE " . $MAP_this->map['account_fields']['username']['map_field'] .
- ' = ' . $db->qstr($old_username);
- $result = $db->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_edit(3)', $db->ErrorMsg());
- return;
- }
- }
-
-
-
-
- ############################################################################
- #>>>>> default Account Deletion method
- ############################################################################
-
- function MAP_account_delete($account_id, $username, $MAP_this)
- {
- ### Check if delete is allowed for this db map:
- if ( !isset($MAP_this->map['account_sync_field']['delete']) ||
- !$MAP_this->map['account_sync_field']['delete'] )
- return false;
-
- ### Check if username is defined
- if ( $username == '')
- {
- ### Get the username:
- $db = &DB();
- $sql = 'SELECT username FROM ' . AGILE_DB_PREFIX . 'account WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($account_id);
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_delete', $db->ErrorMsg());
- return;
- }
-
- if($result->RecordCount > 0)
- {
- $username = $result->fields['username'];
- }
- }
-
- ###################################################################
- ### Get the remote account ID:
- $dbm = new db_mapping;
- $db2 = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "SELECT " . $MAP_this->map['account_fields']['id']['map_field'] . " FROM " .
- $db_prefix . "" . $MAP_this->map['account_map_field'] . ' WHERE ' .
- $MAP_this->map['account_fields']['username']['map_field'] . " = " .
- $db2->qstr($username);
- $result = $db2->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','Map_account_delete', $db2->ErrorMsg());
- return;
- }
-
- $fld = $MAP_this->map['account_fields']['id']['map_field'];
- $remote_account_id = $result->fields[$fld];
-
- ####################################################################
- ### Delete the remote account:
- $sql = "DELETE FROM " .
- $db_prefix . "" . $MAP_this->map['account_map_field'] . ' WHERE ' .
- $MAP_this->map['account_fields']['id']['map_field'] . " = " .
- $db2->qstr($remote_account_id);
- $result = $db2->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_delete', $db->ErrorMsg());
- return;
- }
-
- ####################################################################
- ### Delete the remote groups:
- if ( $MAP_this->map['group_type'] == 'db' || $MAP_this->map['group_type'] == 'hardcode' )
- {
- $sql = "DELETE FROM " .
- $db_prefix . "" . $MAP_this->map['group_account_map']['table'] . ' WHERE ' .
- $MAP_this->map['group_account_map']['account_id'] . " = " .
- $db2->qstr($remote_account_id);
- $result = $db2->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_delete', $db->ErrorMsg());
- return;
- }
-
- return $remote_account_id;
- }
- }
-
-
-
-
-
-
- ########################################################################
- #>>>>> default Account Import method
- ########################################################################
-
- function MAP_account_import($remote_account_id, $MAP_this)
- {
- ####################################################################
- ### Get the remote account details:
- $dbm = new db_mapping;
- $db2 = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "SELECT * FROM " .
- $db_prefix . "" . $MAP_this->map['account_map_field'] . ' WHERE ' .
- $MAP_this->map['account_fields']['id']['map_field'] . " = " .
- $db2->qstr($remote_account_id);
- $result = $db2->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_import', $db2->ErrorMsg());
- return;
- }
-
- if ($result->RecordCount() == 0) return false;
-
- ####################################################################
- ### get a unique account id:
-
- $db = &DB();
- $account_id = $db->GenID(AGILE_DB_PREFIX . 'account_id');
-
- $fld = $MAP_this->map['account_fields']['username']['map_field'];
- @$username = $result->fields[$fld];
-
- $fld = $MAP_this->map['account_fields']['password']['map_field'];
- @$password = $result->fields[$fld];
-
- if ( !$MAP_this->map['account_fields']['company']['map_field'] )
- {
- $company = '';
- }
- else
- {
- $fld = $MAP_this->map['account_fields']['company']['map_field'];
- @$company = $result->fields[$fld];
- }
-
- $fld = $MAP_this->map['account_fields']['email']['map_field'];
- @$email = $result->fields[$fld];
-
- $fld = $MAP_this->map['account_fields']['email_type']['map_field'];
- @$email_type = $result->fields[$fld];
-
- $fld = $MAP_this->map['account_fields']['date_last']['map_field'];
- @$date_last = $result->fields[$fld];
- if ($date_last <= 0) $date_last = time();
-
- $fld = $MAP_this->map['account_fields']['date_orig']['map_field'];
- @$date_orig = $result->fields[$fld];
- if ($date_orig <= 0) $date_orig = time();
-
-
- if ( !$MAP_this->map['account_fields']['last_name']['map_field'] )
- {
- $status = '1';
- }
- else
- {
- $fld = $MAP_this->map['account_fields']['status']['map_field'];
- @$status = $result->fields[$fld];
- if ($status != '0' && $status != '1') $status = '1';
- }
-
-
- $fld = $MAP_this->map['account_fields']['first_name']['map_field'];
- @$first_name = $result->fields[$fld];
- @$name_arr = explode(' ', $first_name);
-
- if ( !$MAP_this->map['account_fields']['last_name']['map_field'] )
- {
- if (count($name_arr) >= 3)
- {
- @$first_name = $name_arr["0"];
- @$middle_name = $name_arr["1"];
- @$last_name = $name_arr["2"];
- }
- elseif (count($name_arr) == 2)
- {
- @$first_name = $name_arr["0"];
- $middle_name = '';
- @$last_name = $name_arr["1"];
- }
- else
- {
- $middle_name = '';
- $last_name = '';
- }
- }
- else
- {
- $fld = $MAP_this->map['account_fields']['middle_name']['map_field'];
- @$middle_name = $result->fields[$fld];
-
- $fld = $MAP_this->map['account_fields']['last_name']['map_field'];
- @$last_name = $result->fields[$fld];
- }
-
-
-
- ####################################################################
- ### Create the sql update statement
-
- $sql = "INSERT INTO ". AGILE_DB_PREFIX ."account SET
- id = ".$db->qstr($account_id).",
- site_id = ".$db->qstr(DEFAULT_SITE).",
- language_id = ".$db->qstr(DEFAULT_LANGUAGE).",
- affiliate_id= ".$db->qstr(DEFAULT_AFFILIATE).",
- reseller_id = ".$db->qstr(DEFAULT_RESELLER).",
- currency_id = ".$db->qstr(DEFAULT_CURRENCY).",
- theme_id = ".$db->qstr(DEFAULT_THEME).",
- status = ".$db->qstr($status).",
- date_orig = ".$db->qstr($date_orig).",
- date_last = ".$db->qstr($date_last).",
- username = ".$db->qstr($username).",
- password = ".$db->qstr($password).",
- first_name = ".$db->qstr($first_name).",
- middle_name = ".$db->qstr($middle_name).",
- last_name = ".$db->qstr($last_name).",
- company = ".$db->qstr($company).",
- email = ".$db->qstr($email).",
- email_type = ".$db->qstr($email_type);
- $result = $db->Execute($sql);
-
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_import', $db->ErrorMsg() . " --- ". $sql);
- return;
- }
-
-
- ####################################################################
- ### add the user to the default group:
-
- $group_id = $db->GenID(AGILE_DB_PREFIX . "" . 'account_id');
- $sql = '
- INSERT INTO ' . AGILE_DB_PREFIX . 'account_group SET
- id = ' . $db->qstr ( $group_id ) . ',
- site_id = ' . $db->qstr ( DEFAULT_SITE ) . ',
- date_orig = ' . $db->qstr ( time() ) . ',
- group_id = ' . $db->qstr ( DEFAULT_GROUP ) . ',
- account_id = ' . $db->qstr ( $account_id ) . ',
- active = ' . $db->qstr ('1');
- $db->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_import', $db->ErrorMsg());
- return;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ########################################################################
- #>>>>> default Account Import method ( FOR 'DB' based groups... )
- ########################################################################
-
- function MAP_account_group_sync_db($account_id, $MAP_this)
- {
- ### Get the local account details
-
- $db = &DB();
- $sql= 'SELECT username,email FROM '.AGILE_DB_PREFIX.'account WHERE
- site_id = '.$db->qstr(DEFAULT_SITE).' AND
- id = '.$db->qstr($account_id);
- $result = $db->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_db1', $db->ErrorMsg(). ' ---> ' . $sql);
- return;
- }
-
- $user = $result->fields['username'];
- $email = $result->fields['email'];
-
- ### Get the remote account id:
- $dbm = new db_mapping;
- $db2 = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "SELECT " .
- $MAP_this->map['account_fields']['id']['map_field']
- . " FROM " .
- $db_prefix . "" . $MAP_this->map['account_map_field'] . ' WHERE ' .
- $MAP_this->map['account_fields']['username']['map_field'] . " = " .
- $db2->qstr($user);
- $result = $db2->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_db2', $db2->ErrorMsg(). ' ---> ' . $sql);
- return;
- }
-
- $fld_remote_id = $MAP_this->map['account_fields']['id']['map_field'];
- $remote_account_id = $result->fields[$fld_remote_id];
-
- ### Delete all current groups for this account id:
- if(!empty($MAP_this->map['group_account_map']['account_id'])) {
- $sql = "DELETE FROM " .
- $db_prefix . "" . $MAP_this->map['group_account_map']['table']
- . ' WHERE ' .
- $MAP_this->map['group_account_map']['account_id'] . " = " .
- $db2->qstr($remote_account_id);
- $result = $db2->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_db3', $db2->ErrorMsg(). ' ---> ' . $sql);
- return;
- }
- }
-
- ### Get the group_map array for this database map:
- if(!isset($this->group_arr))
- {
- $db = &DB();
- $sql = "SELECT group_map FROM ".AGILE_DB_PREFIX."db_mapping WHERE
- map_file = ".$db->qstr($MAP_this->map['map'])." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_db4', $db->ErrorMsg(). ' ---> ' . $sql);
- return;
- }
- @$MAP_this->group_arr = unserialize( $result->fields['group_map'] );
- }
-
-
- ####################################################################
- ### Determine the groups the selected account is authorize for:
-
- $db = &DB();
- $sql = "SELECT group_id,date_start,date_expire FROM ".
- AGILE_DB_PREFIX."account_group WHERE
- account_id = ".$db->qstr($account_id)." AND
- active = ".$db->qstr(1)." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_db4', $db->ErrorMsg(). ' ---> ' . $sql);
- return;
- }
-
- if($result->RecordCount() == 0) return;
- while( !$result->EOF )
- {
- $start = $result->fields['date_start'];
- $expire = $result->fields['date_expire'];
- $group = $result->fields['group_id'];
-
- ### Group access started and not expired:
- if
- (($expire >= time() || $expire == '' || $expire == '0')
- &&
- ($start <= time() || $start == '' || $start == '0'))
- {
- ### Group is authorized:
- ### Get the associated remote group(s) this account needs
- ### to be added to:
-
- reset ($MAP_this->group_arr);
- while ( list ($key, $val) = each ($MAP_this->group_arr))
- {
- if ($key == $group)
- {
- ### what remote group(s) is this group mapped to?
- while ( list ($remote_group, $add) = each ($val))
- {
- if ($add)
- {
- ### create this group in the remote DB:
- $dbm = new db_mapping;
- $db2 = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "INSERT INTO " .
- $db_prefix . "" .
- $MAP_this->map['group_account_map']['table'] . ' SET ' .
- $MAP_this->map['group_account_map']['group_id'] . " = " .
- $db2->qstr($remote_group) . ", " .
- $MAP_this->map['group_account_map']['account_id'] . " = " .
- $db2->qstr($remote_account_id);
- $group_result = $db2->Execute($sql);
- if ($group_result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_db5', $db2->ErrorMsg(). ' ---> ' . $sql);
- return;
- }
- }
- }
- }
- }
- }
- $result->MoveNext();
- }
- return $remote_account_id;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ########################################################################
- #>>>>> default Account Import method ( FOR 'DB' based groups... )
- ########################################################################
-
- function MAP_account_group_sync_status($account_id, $MAP_this)
- {
- ####################################################################
- ### Get the local account details
-
- $db = &DB();
- $sql= 'SELECT username,email FROM '.AGILE_DB_PREFIX.'account WHERE
- site_id = '.$db->qstr(DEFAULT_SITE).' AND
- id = '.$db->qstr($account_id);
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db->ErrorMsg());
- return;
- }
-
- $user = $result->fields['username'];
- $email = $result->fields['email'];
-
-
-
- ####################################################################
- ### Get the remote account id:
-
- $dbm = new db_mapping;
- $db2 = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "SELECT " .
- $MAP_this->map['account_fields']['id']['map_field']
- . " FROM " .
- $db_prefix . "" . $MAP_this->map['account_map_field'] . ' WHERE ' .
- $MAP_this->map['account_fields']['username']['map_field'] . " = " .
- $db2->qstr($user);
- $result = $db2->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db2->ErrorMsg());
- return;
- }
-
- $fld_remote_id = $MAP_this->map['account_fields']['id']['map_field'];
- $remote_account_id = $result->fields[$fld_remote_id];
-
-
- ####################################################################
- ### Get the group_map array for this database map:
-
- if(!isset($this->group_arr))
- {
- $db = &DB();
- $sql = "SELECT group_map FROM ".AGILE_DB_PREFIX."db_mapping WHERE
- map_file = ".$db->qstr($MAP_this->map['map'])." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db->ErrorMsg());
- return;
- }
-
- @$MAP_this->group_arr = unserialize( $result->fields['group_map'] );
- }
-
-
- ####################################################################
- ### Determine the groups the selected account is authorize for:
-
- $db = &DB();
- $sql = "SELECT group_id,date_start,date_expire FROM ".
- AGILE_DB_PREFIX."account_group WHERE
- account_id = ".$db->qstr($account_id)." AND
- active = ".$db->qstr(1)." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db->ErrorMsg());
- return;
- }
-
- if($result->RecordCount() == 0) return;
-
- $MAP_this->status = 0;
-
- while( !$result->EOF )
- {
- $start = $result->fields['date_start'];
- $expire = $result->fields['date_expire'];
- $group = $result->fields['group_id'];
-
- ### Group access started and not expired:
- if
- (($expire >= time() || $expire == '' || $expire == '0')
- &&
- ($start <= time() || $start == '' || $start == '0'))
- {
- ### Group is authorized:
- ### Get the associated remote group(s) this account needs
- ### to be added to:
-
-
- if(is_array($MAP_this->group_arr))
- {
- reset ($MAP_this->group_arr);
- while ( list ($key, $add) = each ($MAP_this->group_arr))
- {
- if ($key == $group)
- {
- if ($add != '' && gettype($add) != 'string')
- {
- if ( $MAP_this->status < $add )
- $MAP_this->status = $add;
- }
- else
- {
- $MAP_this->status = $add;
- }
- }
- }
- }
- }
- $result->MoveNext();
- }
-
- ### Update the remote account:
- $dbm = new db_mapping;
- $db2 = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "UPDATE " .
- $db_prefix . "" .
- $MAP_this->map['account_map_field'] . ' SET ' .
- $MAP_this->map['account_status_field'] . " = " .
- $db2->qstr($MAP_this->status) . " WHERE " .
- $MAP_this->map['account_fields']['id']['map_field'] . " = " .
- $db2->qstr($remote_account_id);
- $group_result = $db2->Execute($sql);
-
- ### error reporting:
- if ($group_result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db->ErrorMsg());
- return;
- }
- return $remote_account_id;
- }
-
-
-
-
-
-
-
-
-
- ########################################################################
- #>>>>> default Account Import method ( FOR 'DB' based groups... )
- ########################################################################
-
- function MAP_account_group_sync_db_status($account_id, $MAP_this)
- {
- ### Get the local account details
- $db = &DB();
- $sql= 'SELECT username,email FROM '.AGILE_DB_PREFIX.'account WHERE
- site_id = '.$db->qstr(DEFAULT_SITE).' AND
- id = '.$db->qstr($account_id);
- $result = $db->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db->ErrorMsg());
- return;
- }
-
- $user = $result->fields['username'];
- $email = $result->fields['email'];
-
-
- ### Get the remote account id:
- $dbm = new db_mapping;
- $db2 = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "SELECT " .
- $MAP_this->map['account_fields']['id']['map_field']
- . " FROM " .
- $db_prefix . "" . $MAP_this->map['account_map_field'] . ' WHERE ' .
- $MAP_this->map['account_fields']['username']['map_field'] . " = " .
- $db2->qstr($user);
- $result = $db2->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db2->ErrorMsg());
- return;
- }
-
- $fld_remote_id = $MAP_this->map['account_fields']['id']['map_field'];
- $remote_account_id = $result->fields[$fld_remote_id];
-
- ### Get the group_map array for this database map:
- if(!isset($this->group_arr))
- {
- $db = &DB();
- $sql = "SELECT group_map,group_rank FROM ".AGILE_DB_PREFIX."db_mapping WHERE
- map_file = ".$db->qstr($MAP_this->map['map'])." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db->ErrorMsg());
- return;
- }
-
- @$MAP_this->group_arr = unserialize( $result->fields['group_map'] );
- @$MAP_this->group_rank = unserialize( $result->fields['group_rank']);
- }
-
- ### Determine the groups the selected account is authorize for:
- $db = &DB();
- $sql = "SELECT group_id,date_start,date_expire FROM ".
- AGILE_DB_PREFIX."account_group WHERE
- account_id = ".$db->qstr($account_id)." AND
- active = ".$db->qstr(1)." AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
-
- ### error reporting:
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db->ErrorMsg());
- return;
- }
-
- if($result->RecordCount() == 0) return;
-
- $MAP_this->status = 0;
- if($result->RecordCount() == 0) return;
- $rank = 0;
- while( !$result->EOF )
- {
- $start = $result->fields['date_start'];
- $expire = $result->fields['date_expire'];
- $group = $result->fields['group_id'];
-
- ### Group access started and not expired:
- if
- (($expire >= time() || $expire == '' || $expire == '0')
- &&
- ($start <= time() || $start == '' || $start == '0'))
- {
- ### Group is authorized:
- ### Get the associated remote group(s) this account needs
- ### to be added to:
-
- if(!empty($MAP_this->group_arr) && is_array($MAP_this->group_arr))
- {
- reset ($MAP_this->group_arr);
- foreach($MAP_this->group_arr as $key => $val)
- {
- if ($key == $group)
- {
- ### what remote group(s) is this group mapped to?
- foreach($val as $remote_group => $add) {
- if (!empty($add) && $MAP_this->group_rank[$key]['rank'] > $rank)
- {
- $MAP_this->status = $add;
- $rank = $MAP_this->group_rank[$key]['rank'];
- }
- }
- }
- }
- }
- }
- $result->MoveNext();
- }
-
- ### Update the remote account:
- $dbm = new db_mapping;
- $db2 = $dbm->DB_connect(false, $MAP_this->map['map']);
- eval ( '@$db_prefix = DB2_PREFIX'. strtoupper($MAP_this->map['map']) .';' );
- $sql = "UPDATE " .
- $db_prefix . "" .
- $MAP_this->map['account_map_field'] . ' SET ' .
- $MAP_this->map['account_status_field'] . " = " .
- $db2->qstr($MAP_this->status) . " WHERE " .
- $MAP_this->map['account_fields']['id']['map_field'] . " = " .
- $db2->qstr($remote_account_id);
- $group_result = $db2->Execute($sql);
- if ($group_result === false)
- {
- global $C_debug;
- $C_debug->error('db_mapping.inc.php','MAP_account_group_sync_status', $db->ErrorMsg());
- return;
- }
- return $remote_account_id;
- }
-}
-?>
\ No newline at end of file
diff --git a/modules/db_mapping/db_mapping_construct.xml b/modules/db_mapping/db_mapping_construct.xml
deleted file mode 100644
index 1e5d3764..00000000
--- a/modules/db_mapping/db_mapping_construct.xml
+++ /dev/null
@@ -1,90 +0,0 @@
-
-
-
- db_mapping
-
-
-
-
-
- 0
-
- name
-
- 25
-
- name
- status,type
-
-
-
- I8
- 1
-
-
- I4
-
-
- C(128)
- 3
- 128
- any
-
-
- X2
-
-
- L
-
-
- C(16)
-
-
- C(128)
- 1
- 128
- any
-
-
- C(128)
- 2
- 128
- any
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- X
- array
-
-
- X
- array
-
-
- C(128)
- 4
- 128
-
-
-
-
- id,site_id,name,notes,status,type,db_name,db_host,db_user,db_pass,db_prefix,cookie_name,group_map,map_file,group_rank
- id,site_id,name,notes,status,type,db_name,db_host,db_user,db_pass,db_prefix,cookie_name,group_map,map_file,group_rank
- id,site_id,name,notes,status,type,db_name,db_host,db_user,db_pass,db_prefix,cookie_name,group_map,map_file,group_rank
- id,site_id,name,notes,status,type,db_name,db_host,db_user,db_pass,db_prefix,cookie_name,group_map,map_file,group_rank
- id,site_id,name,notes,status,type,db_name,db_host,db_user,db_pass,db_prefix,cookie_name,group_map,map_file,group_rank
-
-
- 0
-
diff --git a/modules/db_mapping/db_mapping_install.xml b/modules/db_mapping/db_mapping_install.xml
deleted file mode 100644
index 8bf1e345..00000000
--- a/modules/db_mapping/db_mapping_install.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
- db_mapping
- setup
-
- 1
-
-
-
-
- view
-
- 1
-
-
- add
-
-
- update
-
-
- search
-
-
- delete
-
-
- search_show
-
-
- sync
-
-
-
-
\ No newline at end of file
diff --git a/modules/discount/discount.inc.php b/modules/discount/discount.inc.php
index 0c055038..7850d3d6 100644
--- a/modules/discount/discount.inc.php
+++ b/modules/discount/discount.inc.php
@@ -1,25 +1,34 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:Discount
*/
-
-class discount
-{
+
+/**
+ * The main AgileBill Discount Class
+ *
+ * @package AgileBill
+ * @subpackage Module:Discount
+ */
+class discount extends OSB_module {
/**
* array of available discounts
*
@@ -48,13 +57,6 @@ class discount
*/
var $plugins=false;
- /**
- * Setup the discount plugin array if needed
- */
- function discount() {
- // $this->plugins = array('test');
- }
-
/**
* Load a specific discount plugin and validate the results
*
@@ -358,22 +360,6 @@ class discount
return true;
}
-
- function discount_construct() {
- $this->module = "discount";
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
function user_search($VAR) {
# Lock the user only for his billing_records:
if(!SESS_LOGGED) {
@@ -381,7 +367,6 @@ class discount
}
# Lock the account_id
$VAR['discount_avail_account_id'] = SESS_ACCOUNT;
- $this->discount_construct();
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
@@ -393,61 +378,13 @@ class discount
if(!SESS_LOGGED) {
return false;
}
- $this->discount_construct();
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$db = new CORE_database;
$db->search_show($VAR, $this, $type);
}
- function add($VAR) {
- $this->discount_construct();
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- function view($VAR) {
- $this->discount_construct();
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- function update($VAR) {
- $this->discount_construct();
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- function delete($VAR) {
- $this->discount_construct();
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- function search_form($VAR) {
- $this->discount_construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- function search($VAR) {
- $this->discount_construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
function search_show($VAR) {
- $this->discount_construct();
$type = "search";
$this->method["$type"] = explode(",", $this->method["$type"]);
$dbc = new CORE_database;
@@ -477,4 +414,4 @@ class discount
$smarty->assign('discount', $smart);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/discount/discount_construct.xml b/modules/discount/discount_construct.xml
index ed463398..995dd409 100644
--- a/modules/discount/discount_construct.xml
+++ b/modules/discount/discount_construct.xml
@@ -1,120 +1,176 @@
-
- discount
-
-
-
-
-
- 0
-
- name
-
- 25
-
-
- date_start
- date_expire
- status
-
-
-
-
- I8
- 1
- 1
-
-
- I4
- 1
-
-
- I8
- date-now
-
-
- I8
- date
-
-
- I8
- date
-
-
- L
-
-
- C(64)
- 2
- 32
- any
-
-
- X2
-
-
- I4
-
-
- I4
-
-
- I8
-
-
- X2
- country
- name
- array
-
-
- X2
- array
-
-
- X2
- array
-
-
- L
-
-
- L
-
-
- F
-
-
- F
-
-
- F
-
-
- L
-
-
- L
-
-
- F
-
-
- F
-
-
- F
-
-
-
-
- id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,avail_product_id,avail_group_id,avail_tld_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
- id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,avail_product_id,avail_group_id,avail_tld_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
- id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,avail_product_id,avail_group_id,avail_tld_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
- id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,avail_product_id,avail_group_id,avail_tld_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
- id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
-
-
- 0
+
+ discount
+
+
+
+
+
+ 0
+
+ name
+
+ 25
+
+ 0
+
+
+
+ date_start
+ date_expire
+ status
+
+
+
+
+
+
+ 1
+ I8
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ Active
+ L
+
+
+ date
+ Date Start
+ I8
+
+
+ date
+ Date End
+ I8
+
+
+ Name
+ 2
+ 32
+ C(64)
+ any
+
+
+ Notes
+ X2
+
+
+ I4
+
+
+ I4
+
+
+ Account
+ I8
+
+
+ Product
+ X2
+ country
+ name
+ array
+
+
+ array
+ Group
+ X2
+
+
+ array
+ Domain
+ X2
+
+
+ L
+
+
+ L
+
+
+ F
+
+
+ F
+
+
+ F
+
+
+ L
+
+
+ L
+
+
+ F
+
+
+ F
+
+
+ F
+
+
+
+
+
+ date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,avail_product_id,avail_group_id,avail_tld_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
+ id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,avail_product_id,avail_group_id,avail_tld_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
+ id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,avail_product_id,avail_group_id,avail_tld_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
+ id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,avail_product_id,avail_group_id,avail_tld_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
+ id,site_id,date_orig,date_start,date_expire,status,name,notes,max_usage_account,max_usage_global,avail_account_id,new_status,new_type,new_rate,new_max_discount,new_min_cost,recurr_status,recurr_type,recurr_rate,recurr_max_discount,recurr_min_cost
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ name
+
+
+ status
+
+
+ orders
+ invoice_count
+
+
+ revenue
+ revenue
+
+
+ savings
+ savings
+
+
+ new_type
+
+
+
diff --git a/modules/discount/discount_install.xml b/modules/discount/discount_install.xml
index cfb721d2..a3127bbb 100644
--- a/modules/discount/discount_install.xml
+++ b/modules/discount/discount_install.xml
@@ -1,39 +1,59 @@
+
+
- discount
- account_admin
-
+
+
+
+ Discounts
+
1
+
+ discount
+
+
+
+ account
+
+
+
+ base
-
-
-
- search
-
- 1
-
-
- view
-
- 1
-
-
- delete
-
-
- update
-
-
- add
-
- 1
-
-
- search_form
-
-
- search_show
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/email_log/email_log.inc.php b/modules/email_log/email_log.inc.php
index cf3db10d..1d6b765c 100644
--- a/modules/email_log/email_log.inc.php
+++ b/modules/email_log/email_log.inc.php
@@ -1,118 +1,79 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Modules:EmailLog
*/
-
-class email_log
-{
+
+/**
+ * The main AgileBill Email Log Class
+ *
+ * @package AgileBill
+ * @subpackage Modules:EmailLog
+ */
+class email_log extends OSB_module {
var $user_view_count = 25; /* show last X email logs for user */
-
- function user_list($VAR) {
- if(!SESS_LOGGED) return false;
- $db=&DB();
- $email = $db->GetOne("select email from ".AGILE_DB_PREFIX."account where id = ".SESS_ACCOUNT);
- $rs=$db->Execute(sqlSelect($db,"email_log","id,email,date_orig,subject,urgent,userread",
- "email=::$email:: and account_id=".SESS_ACCOUNT,'date_orig',$this->user_view_count));
- if($rs && $rs->RecordCount()) {
- $smart=array();
- while(!$rs->EOF) {
- array_push($smart, $rs->fields);
- $rs->MoveNext();
+
+ public function user_list($VAR) {
+ if (! SESS_LOGGED)
+ return false;
+
+ $db = &DB();
+
+ $email = $db->GetOne(sqlSelect($db,'account','email',array('id'=>SESS_ACCOUNT)));
+ $rs = $db->Execute(
+ sqlSelect($db,'email_log','id,email,date_orig,subject,urgent,userread',array('email'=>$email,'account_id'=>SESS_ACCOUNT),'date_orig',$this->user_view_count));
+
+ if ($rs && $rs->RecordCount()) {
+ $smart = array();
+ while (! $rs->EOF) {
+ array_push($smart,$rs->fields);
+ $rs->MoveNext();
}
+
global $smarty;
- $smarty->assign('email_log', $smart);
- }
- }
-
- function user_view($VAR) {
- /* validate, update to read, and view() */
- if(!SESS_LOGGED || empty($VAR['id'])) return false;
- /* select id for this user */
- $db=&DB();
- $rs = $db->Execute(sqlSelect($db,"email_log","*","id=::{$VAR['id']}:: and account_id=".SESS_ACCOUNT));
- if($rs && $rs->RecordCount()) {
- global $smarty;
- $smarty->assign('email_log', $rs->fields);
- if($rs->fields['userread'] != 1) {
- /* update to read */
- $fields=Array('userread'=>1);
- $db->Execute(sqlUpdate($db,"email_log",$fields,"id = {$rs->fields['id']}"));
- }
+ $smarty->assign('email_log',$smart);
}
}
-
+
+ public function user_view($VAR) {
+ if (! SESS_LOGGED || empty($VAR['id']))
+ return false;
+
+ $db = &DB();
+
+ $rs = $db->Execute(sqlSelect($db,'email_log','*',array('id'=>$VAR['id'],'account_id'=>SESS_ACCOUNT)));
+ if ($rs && $rs->RecordCount()) {
+ global $smarty;
+
+ $smarty->assign('email_log',$rs->fields);
+ # Update to read
+ if ($rs->fields['userread'] != 1)
+ $db->Execute(sqlUpdate($db,'email_log',array('userread'=>1),array('id'=>$rs->fields['id'])));
+ }
+ }
+
function add($account_id, $subject, $message, $email, $html=0, $urgent=0) {
$db=&DB();
$fields=Array('date_orig'=>time(), 'account_id'=>$account_id, 'subject'=>$subject, 'message'=>$message, 'email'=>$email, 'html'=>$html, 'urgent'=>$urgent, 'userread'=>0);
$id = & $db->Execute(sqlInsert($db,"email_log",$fields));
}
-
- function view($VAR) {
- $this->construct();
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- function delete($VAR) {
- $this->construct();
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- function search_form($VAR) {
- $this->construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- function search($VAR) {
- $this->construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- function search_show($VAR) {
- $this->construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
- function construct() {
- $this->module = "email_log";
- $this->xml_construct = PATH_MODULES . $this->module . "/" . $this->module . "_construct.xml";
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/email_log/email_log_construct.xml b/modules/email_log/email_log_construct.xml
index 1a5745ff..34a8ffac 100644
--- a/modules/email_log/email_log_construct.xml
+++ b/modules/email_log/email_log_construct.xml
@@ -1,55 +1,107 @@
-
- email_log
-
- setup
- 0
- date_orig
- 35
+
+
+ email_log
+
+
+
+ setup
+
+ 0
+
+ date_orig
+
+ 25
+
+ 1
+
+
id,site_id,account_id
email
html,urgent,userread
-
-
- I8
- 1
-
-
- I4
-
-
- I8
- date-now
-
-
- I4
- any
-
-
- C(128)
-
-
- C(128)
-
-
- X2
-
-
- L
-
-
- L
-
-
- L
-
-
-
- id,site_id,date_orig,account_id,email,subject,message,html,urgent,userread
- id,site_id,date_orig,account_id,email,subject,message,html,urgent,userread
- id,site_id,date_orig,account_id,email,subject,message,html,urgent,userread
-
-
-
\ No newline at end of file
+
+
+
+
+
+ 1
+ I8
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+ I4
+ any
+
+
+ Email Address
+ C(128)
+
+
+ Subject
+ C(128)
+
+
+ Message
+ X2
+
+
+ L
+
+
+ L
+
+
+ L
+
+
+
+
+
+ id,site_id,date_orig,account_id,email,subject,message,html,urgent,userread
+ id,site_id,date_orig,account_id,email,subject,message,html,urgent,userread
+ id,site_id,date_orig,account_id,email,subject,message,html,urgent,userread
+
+
+
+
+
+
+
+ Emails
+ Email
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ date_orig
+ date
+
+
+ email
+
+
+ subject
+
+
+
+
diff --git a/modules/email_log/email_log_install.xml b/modules/email_log/email_log_install.xml
index c500c944..acee29f1 100644
--- a/modules/email_log/email_log_install.xml
+++ b/modules/email_log/email_log_install.xml
@@ -1,34 +1,51 @@
-
+
+
- email_log
- setup
- Stores log of all e-mails sent out to accounts
- 1
- setup
-
-
-
-
-
- delete
-
-
- view
- core:search&module=%%&_escape=1
- 1
-
-
- search
- %%:search_form
- 1
-
-
- search_form
-
-
- search_show
-
-
-
-
\ No newline at end of file
+
+ setup
+
+ Email Log
+
+ 1
+
+ email_log
+
+
+
+ setup
+
+
+
+
+
+
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ Search
+ 1
+ search_form
+
+
+
+ search_show
+
+
+
+ view
+
+
+
+
diff --git a/modules/email_queue/email_queue.inc.php b/modules/email_queue/email_queue.inc.php
index f36f0bcc..f2fc2d1a 100644
--- a/modules/email_queue/email_queue.inc.php
+++ b/modules/email_queue/email_queue.inc.php
@@ -1,189 +1,67 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:EmailQueue
*/
-
-class email_queue
-{
- # Open the constructor for this mod
- function email_queue()
- {
- # name of this module:
- $this->module = "email_queue";
+/**
+ * The main AgileBill Email Queue Class
+ *
+ * @package AgileBill
+ * @subpackage Module:EmailQueue
+ */
+class email_queue extends OSB_module {
+ /**
+ * Send mails in the queue
+ */
+ public function send($VAR) {
+ $db = &DB();
+ $rs = $db->Execute(sqlSelect($db,'email_queue','*',array('status'=>0)));
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
+ if ($rs && $rs->RecordCount()) {
+ require_once(PATH_MODULES.'email_template/email_template.inc.php');
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
+ while (! $rs->EOF) {
+ # Get values
+ $sql = array();
+ $sql[1] = $rs->fields['sql1'];
+ $sql[2] = $rs->fields['sql2'];
+ $sql[3] = $rs->fields['sql3'];
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
- ##############################
- ## SEND E-MAILS IN QUEUE ##
- ##############################
- function send($VAR)
- {
- $VAR_ORIG = $VAR;
-
- $db = &DB();
- $dbm = new CORE_database;
- $sql = $dbm->sql_select("email_queue", "*", "status = 0", "", $db);
- $rs = $db->Execute($sql);
-
- if($rs != false && $rs->RecordCount() > 0)
- {
- require_once ( PATH_MODULES . 'email_template/email_template.inc.php' );
- while(!$rs->EOF)
- {
- # Get values
- global $VAR;
- $VAR = unserialize($rs->fields['var']);
-
- $sql1 = $rs->fields['sql1'];
- $sql2 = $rs->fields['sql2'];
- $sql3 = $rs->fields['sql3'];
-
- if(!empty($sql1)) {
- if(ereg("^a:", $sql1) && is_array(unserialize($sql1))) $sql1 = unserialize($sql1);
- } else {
- $sql1 = false;
- }
-
- if(!empty($sql2)) {
- if(ereg("^a:", $sql2) && is_array(unserialize($sql2))) $sql2 = unserialize($sql2);
- } else {
- $sql2 = false;
- }
-
- if(!empty($sql3)) {
- if(ereg("^a:", $sql3) && is_array(unserialize($sql3))) $sql3 = unserialize($sql3);
- } else {
- $sql3 = false;
- }
+ # Unserialize the SQL data if required.
+ foreach ($sql as $i)
+ if (preg_match('/^a:/',$sql[$i]) && is_array($a = unserialize($sql[$a])))
+ $sql[$i] = $a;
# Send email
$mail = new email_template;
- $result = $mail->send($rs->fields['email_template'], $rs->fields['account_id'], $sql1, $sql2, $sql3, false);
+ $result = $mail->send($rs->fields['email_template'],$rs->fields['account_id'],$sql[1],$sql[2],$sql[3],false);
# Update to sent status
- if($result)
- {
- $sql = "UPDATE ".AGILE_DB_PREFIX."email_queue SET
- status = 1
- WHERE
- id = {$rs->fields['id']}
- AND
- site_id = ".DEFAULT_SITE;
- $db->Execute($sql);
- }
+ if ($result)
+ $db->Execute(sqlUpdate($db,'email_queue',array('status'=>1),array('id'=>$rs->fields['id'])));
+
$rs->MoveNext();
}
}
-
- $VAR = $VAR_ORIG;
}
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/email_queue/email_queue_construct.xml b/modules/email_queue/email_queue_construct.xml
index 6bca2ae4..77f7ff44 100644
--- a/modules/email_queue/email_queue_construct.xml
+++ b/modules/email_queue/email_queue_construct.xml
@@ -1,78 +1,126 @@
+
+ email_queue
+
+
+
+
+
+ 0
+
+ id
+
+ 25
+
+ 0
-
- email_queue
+
+
+
-
-
+
+
+
+
+ 1
+ I8
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ date-now
+ Date Updated
+ I8
+
+
+
+ Processed
+ L
+
+
+ Account
+ C(128)
+
+
+ Email Template
+ C(128)
+
+
+ Data Field 1
+ C(128)
+
+
+ Data Field 2
+ C(128)
+
+
+ Data Field 3
+ C(128)
+
+
+ Data Field 4
+ C(128)
+
+
+ Data Field 5
+ C(128)
+
+
+ Data Variables
+ X2
+
+
-
-
+
+
+ id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
+ id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
+ id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
+ id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
+ id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
+
-
- 0
+
+
-
- id
+
+
+
-
- 35
-
-
-
-
- I8
-
-
- I4
-
-
- I8
- time
-
-
- I8
- date-now
-
-
- L
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- X2
-
-
-
-
-
- id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
- id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
- id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
- id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
- id,site_id,date_orig,date_last,status,account_id,email_template,sql1,sql2,sql3,sql4,sql5,var
-
-
-
- 0
-
\ No newline at end of file
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ date_orig
+ date
+
+
+ account_id
+
+
+ email_template
+
+
+ status
+ bool
+
+
+
+
diff --git a/modules/email_queue/email_queue_install.xml b/modules/email_queue/email_queue_install.xml
index 8cdd8825..0f3b53ae 100644
--- a/modules/email_queue/email_queue_install.xml
+++ b/modules/email_queue/email_queue_install.xml
@@ -1,22 +1,29 @@
+
+
+
+
+
+
+
+ 0
+
+ email_queue
+
+
+
+ email_queue
+
+
+
+ base
+
-
-
- email_queue
- account_admin
- Stores the email queue for future mailing
-
-
-
-
-
-
-
-
-
- add
-
-
-
-
\ No newline at end of file
+
+
+
+ add
+
+
+
diff --git a/modules/email_template/email_template.inc.php b/modules/email_template/email_template.inc.php
index 5cbefd6b..aac54b07 100644
--- a/modules/email_template/email_template.inc.php
+++ b/modules/email_template/email_template.inc.php
@@ -1,527 +1,329 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:Mail
*/
/**
+ * The main AgileBill Mail Template Class
+ *
* include_once(PATH_MODULES.'email_template/email_template.inc.php');
* $my = new email_template;
- * $my->send('newsletter_subscribe', '4d1800b401f5d340f022688de0ac2687', 'f1714072da3c05a220ac3b60a3a57d88', '2', '3');
+ * $my->send('newsletter_subscribe','4d1800b401f5d340f022688de0ac2687','f1714072da3c05a220ac3b60a3a57d88','2','3');
+ *
+ * @package AgileBill
+ * @subpackage Module:Mail
*/
-class email_template
-{
- var $debug=false;
-
- # Open the constructor for this mod
- function construct()
- {
- # name of this module:
- $this->module = "email_template";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $this->construct();
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $this->construct();
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $this->construct();
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $this->construct();
- $this->associated_DELETE[] = Array( 'table' => 'email_template_translate',
- 'field' => 'email_template_id');
-
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $this->construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $this->construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $this->construct();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
-
-
-
- ##############################
- ## SEND EMAIL TEMPLATE ##
- ##############################
-
- function send($template, $acct, $sql1, $sql2, $sql3, $queue=true)
- {
- global $VAR, $C_debug;
+class email_template extends OSB_module {
+ /**
+ * Send or Queue template based email
+ *
+ * Prefixing the template with "admin->" will result in the mail being
+ * sent to the admin only.
+ *
+ * @param string $template_name Name of template to use
+ * @param int $acct Account ID or email address
+ */
+ public function send($template_name,$acct,$sql1,$sql2,$sql3,$queue=true) {
+ global $VAR,$C_debug,$C_list;
$db = &DB();
- # Send to admin only?
+ # Send to admin only?
$admin_only = false;
- if(eregi('admin->', $template)) {
+ if (preg_match('/^admin->/',$template_name)) {
$admin_only = true;
- $template = eregi_replace('admin->', '', $template);
- }
+ $template_name = preg_replace('/^admin->/','',$template_name);
+ }
+ $template = $db->Execute(sqlselect($db,'email_template','*',array('name'=>$template_name)));
- ############################################################
- ### Get the template settings
+ # If the template is not active, return.
+ if (! $template || $template->fields['status'] != '1')
+ return;
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."email_template WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- name = ".$db->qstr($template);
- $template = $db->Execute($q);
- if($template->fields['status'] != '1')
- return;
+ # Setup our Email
+ $E = array();
- $E['priority'] = $template->fields["priority"];
+ # Email Priority
+ $E['priority'] = $template->fields['priority'];
- ############################################################
- ### Get the setup_email settings
-
- if(empty($template->fields["setup_email_id"]))
+ # Get the setup_email settings
+ if (empty($template->fields['setup_email_id']))
$setup_email_id = DEFAULT_SETUP_EMAIL;
else
- $setup_email_id = $template->fields["setup_email_id"];
+ $setup_email_id = $template->fields['setup_email_id'];
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."setup_email WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- id = ".$db->qstr($setup_email_id);
- $setup_email = $db->Execute($q);
+ $setup_email = $db->Execute(sqlSelect($db,'setup_email','*',array('id'=>$setup_email_id)));
- ### E-mail queue?
- if($setup_email->fields['queue'] == 1 && $queue)
- {
+ # Queue the email
+ if ($queue && $C_list->is_installed('email_queue') && $setup_email->fields['queue']) {
# Set sql vars
- if(is_array($sql1)) $sql1 = serialize($sql1);
- if(is_array($sql2)) $sql2 = serialize($sql2);
- if(is_array($sql3)) $sql3 = serialize($sql3);
- if(is_array($VAR)) $var = serialize($VAR);
- if(@$admin_only)
- $sql_template = "admin->".$template->fields['name'];
+ if (is_array($sql1))
+ $sql1 = serialize($sql1);
+ if (is_array($sql2))
+ $sql2 = serialize($sql2);
+ if (is_array($sql3))
+ $sql3 = serialize($sql3);
+ if (is_array($VAR))
+ $var = serialize($VAR);
+
+ # If this was an admin only email, we need to rewrite the template name again.
+ if ($admin_only)
+ $sql_template = sprintf('admin->%s',$template->fields['name']);
else
$sql_template = $template->fields['name'];
- # Check that this email is not already in the queue:
- $q = "SELECT id FROM ".AGILE_DB_PREFIX."email_queue WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- status = 0 AND
- account_id = '$acct' AND
- email_template= ".$db->qstr($sql_template)." AND
- sql1 = ".$db->qstr(@$sql1)." AND
- sql2 = ".$db->qstr(@$sql2)." AND
- sql3 = ".$db->qstr(@$sql3);
- $duplicates = $db->Execute($q);
- if($duplicates != false && $duplicates->RecordCount() > 0)
- return;
+ # Check that this email is not already in the queue
+ $duplicates = $db->Execute(sqlSelect($db,'email_queue','id',
+ array('status'=>0,'account_id'=>$acct,'email_template'=>$sql_template,'sql1'=>$sql1,'sql2'=>$sql2,'sql3'=>$sql3)
+ ));
+ if ($duplicates != false && $duplicates->RecordCount() > 0)
+ return;
- # queue this e-mail:
- $id = $db->GenID(AGILE_DB_PREFIX.'email_queue_id');
- $sql = "INSERT INTO ".AGILE_DB_PREFIX."email_queue SET
- id = $id,
- site_id = ".DEFAULT_SITE.",
- date_orig = ".time().",
- date_last = ".time().",
- status = 0,
- account_id = '$acct',
- email_template= ".$db->qstr($sql_template).",
- sql1 = ".$db->qstr(@$sql1).",
- sql2 = ".$db->qstr(@$sql2).",
- sql3 = ".$db->qstr(@$sql3).",
- var = ".$db->qstr(@$var);
- $db->Execute($sql);
- return;
- }
-
- if($setup_email->fields['type'] == 0) {
- $type = 0;
- } else {
- $type = 1;
- $E['server'] = $setup_email->fields['server'];
- $E['account'] = $setup_email->fields['username'];
- $E['password'] = $setup_email->fields['password'];
- }
-
- $E['from_name'] = $setup_email->fields['from_name'];
- $E['from_email'] = $setup_email->fields['from_email'];
-
- if($setup_email->fields['cc_list'] != '')
- $E['cc_list'] = explode(',', $setup_email->fields['cc_list']);
-
- if($setup_email->fields['bcc_list'] != '')
- $E['bcc_list'] = explode(',', $setup_email->fields['bcc_list']);
-
-
-
- ############################################################
- ### Get the account settings
-
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."account WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- (
- email = ".$db->qstr($acct)." OR
- id = ".$db->qstr($acct). "
- )";
- $account = $db->Execute($q);
- if($account == false)
- {
- $C_debug->error('email_template.inc.php','send1', $db->ErrorMsg() . " " . $sql);
- return false;
- }
- else
- {
- if($admin_only == false)
- {
- if($account->RecordCount() > 0) {
- $E['to_email'] = $account->fields['email'];
- $E['to_name'] = $account->fields['first_name'] . ' ' . $account->fields['last_name'];
- $this->ab_account = true;
- } else {
- $E['to_email'] = $acct;
- $E['to_name'] = $acct;
- $this->ab_account = false;
- }
- } else {
- $E['to_email'] = $setup_email->fields['from_email'];
- $E['to_name'] = $setup_email->fields['from_name'];
- $this->ab_account = true;
- }
- }
-
-
- ############################################################
- ### Get the template translation for the specified account for text/htm
-
- if(@$this->ab_account && @$account->fields["language_id"] != "")
- $language_id = $account->fields["language_id"];
- else
- $language_id = DEFAULT_LANGUAGE;
-
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."email_template_translate WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- language_id = ".$db->qstr($language_id)." AND
- email_template_id = ".$db->qstr($template->fields["id"]);
- $setup_email = $db->Execute($q);
-
- if(!$setup_email || !$setup_email->RecordCount()) {
- # get the default translation for this email:
- $q = "SELECT * FROM ".AGILE_DB_PREFIX."email_template_translate WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- language_id = ".$db->qstr(DEFAULT_LANGUAGE)." AND
- email_template_id = ".$db->qstr($template->fields["id"]);
- $setup_email = $db->Execute($q);
- }
-
- if(!$setup_email || !$setup_email->RecordCount()) {
- # unable to locate translation!
- global $C_debug;
- $message = 'Unable to locate translation for Email Template "'.$template->fields['name'].'" and Language "'. $language_id .'" OR "' . DEFAULT_LANGUAGE . '"';
- $C_debug->error('email_template.inc.php','send', $message);
+ # Queue this Email
+ $db->Execute(sqlInsert($db,'email_queue',array(
+ 'date_orig'=>time(),
+ 'date_last'=>time(),
+ 'status'=>0,
+ 'account_id'=>$acct,
+ 'email_template'=>$sql_template,
+ 'sql1'=>$sql1,
+ 'sql2'=>$sql2,
+ 'sql3'=>$sql3,
+ 'var'=>$var)
+ ));
return;
}
-
- # set the subject:
- $E['subject'] = $setup_email->fields['subject'];
-
- # determine whether to send HTML or not...
- if(@$this->ab_account && $account->fields['email_type'] == 1) {
- if(!empty($setup_email->fields['message_html'])) {
- $E['body_html'] = $setup_email->fields['message_html'];
- $E['html'] = '1';
- } else {
- $E['body_html'] = false;
- $E['html'] = '0';
- }
- } else {
- $E['html'] = '0';
+ # Is this an SMTP connection
+ if ($setup_email->fields['type'] == 1) {
+ $E['server'] = $setup_email->fields['server'];
+ $E['account'] = $setup_email->fields['username'];
+ $E['password'] = $setup_email->fields['password'];
}
- $E['body_text'] = $setup_email->fields['message_text'];
+ $E['from_name'] = $setup_email->fields['from_name'];
+ $E['from_email'] = $setup_email->fields['from_email'];
- ### Get the date-time
+ if ($setup_email->fields['cc_list'])
+ $E['cc_list'] = explode(',',$setup_email->fields['cc_list']);
+
+ if ($setup_email->fields['bcc_list'])
+ $E['bcc_list'] = explode(',',$setup_email->fields['bcc_list']);
+
+ # Get the account settings
+ $account = $db->Execute($q=sqlSelect($db,'account','*',sprintf('(email=::%s:: OR id=::%s::)',$acct,$acct)));
+ if (! $account) {
+ $C_debug->error(__FILE__,__METHOD__,sprintf('%s %s',$db->ErrorMsg(),$q));
+
+ return false;
+ }
+
+ if ($admin_only) {
+ $E['to_email'] = $setup_email->fields['from_email'];
+ $E['to_name'] = $setup_email->fields['from_name'];
+ $ab_account = true;
+
+ } else {
+ if ($account->RecordCount() > 0) {
+ $E['to_email'] = $account->fields['email'];
+ $E['to_name'] = sprintf('%s %s',$account->fields['first_name'],$account->fields['last_name']);
+ $ab_account = true;
+
+ } else {
+ $E['to_email'] = $acct;
+ $E['to_name'] = $acct;
+ $ab_account = false;
+ }
+ }
+
+ # Get the template translation for the specified account for text/htm
+ if ($ab_account && $account->fields['language_id'])
+ $language_id = $account->fields['language_id'];
+ else
+ $language_id = DEFAULT_LANGUAGE;
+
+ $email_template_translate = $db->Execute(sqlSelect($db,'email_template_translate','*',array('language_id'=>$language_id,'email_template_id'=>$template->fields['id'])));
+
+ # If there is no translation, get the default translation for this email
+ if (! $email_template_translate || ! $email_template_translate->RecordCount())
+ $email_template_translate = $db->Execute(sqlSelect($db,'email_template_translate','*',array('language_id'=>DEFAULT_LANGUAGE,'email_template_id'=>$template->fields['id'])));
+
+ # Unable to locate translation?
+ if (! $email_template_translate || ! $email_template_translate->RecordCount()) {
+ global $C_debug;
+
+ $C_debug->error(__FILE__,__METHOD__,
+ sprintf('Unable to locate translation for Email Template %s and Language %s OR %s',$template->fields['name'],$language_id,DEFAULT_LANGUAGE));
+
+ return;
+ }
+
+ # Set the subject:
+ $E['subject'] = $email_template_translate->fields['subject'];
+
+ # Determine whether to send HTML or not...
+ if ($ab_account && $account->fields['email_type'] == 1) {
+ if (! empty($email_template_translate->fields['message_html'])) {
+ $E['body_html'] = $email_template_translate->fields['message_html'];
+ $E['html'] = '1';
+
+ } else {
+ $E['body_html'] = false;
+ $E['html'] = '0';
+ }
+
+ } else {
+ $E['html'] = '0';
+ }
+
+ $E['body_text'] = $email_template_translate->fields['message_text'];
+
+ # Get the date-time
include_once(PATH_CORE.'list.inc.php');
- $C_list = new CORE_list;
- $date = $C_list->date_time(time());
+ $cl = new CORE_list;
- ### Url formatting...
- if($admin_only) {
+ $date = $cl->date_time(time());
+
+ # Url formatting.
+ if ($admin_only) {
$site_url = URL.'admin.php';
$site_ssl_url = SSL_URL.'admin.php';
+
} else {
$site_url = URL;
- $site_ssl_url = SSL_URL;
+ $site_ssl_url = SSL_URL;
}
- ### Get the replace vars from the email template:
- $replace = Array('%site_name%' => $E['from_name'],
- '%site_email%' => $E['from_email'],
- '%url%' => $site_url,
- '%date%' => $date,
- '%ssl_url%' => $site_ssl_url);
+ # Get the replace vars from the email template:
+ $replace = array(
+ '%site_name%' => $E['from_name'],
+ '%site_email%' => $E['from_email'],
+ '%url%' => $site_url,
+ '%date%' => $date,
+ '%ssl_url%' => $site_ssl_url);
- ### Get the replace vars from the $VAR variable:
- reset($VAR);
- while(list($key, $value) = each($VAR))
- {
- $re_this = "%var_".$key."%";
+ # Include the replace vars from the $VAR variable:
+ foreach ($VAR as $key => $value) {
+ $re_this = sprintf('%%var_%s%%',$key);
$replace[$re_this] = $value;
}
- ### Get the replace vars from the account:
+ # Get the replace vars from the account
$replace['%acct_id%'] = $acct;
- if(@$this->ab_account) {
- while(list($key, $value) = each($account->fields)) {
- $re_this = "%acct_".$key."%";
+ if ($ab_account)
+ foreach ($account->fields as $key => $value) {
+ $re_this = sprintf('%%acct_%s%%',$key);
$replace[$re_this] = $value;
- }
- }
-
- ############################################################
- ### Get the SQL1 Query/Arrays
- if(!empty($template->fields["sql_1"]) && !empty($sql1) &&!is_array($sql1))
- {
- $sql = eregi_replace('%DB_PREFIX%', AGILE_DB_PREFIX, $template->fields["sql_1"]);
- $sql = eregi_replace('%SQL1%', $db->qstr($sql1), $sql);
- if(!is_array($sql2))
- $sql = eregi_replace('%SQL2%', $db->qstr($sql2), $sql);
- if(!is_array($sql3))
- $sql = eregi_replace('%SQL3%', $db->qstr($sql3), $sql);
- $sql .= " AND site_id = ". $db->qstr(DEFAULT_SITE);
- $SQL_1 = $db->Execute($sql);
-
- if($SQL_1 == false)
- {
- ### return the error message
- global $C_debug;
- $C_debug->error('email_template.inc.php','send', $db->ErrorMsg() . " " . $sql);
}
- else if($SQL_1->RecordCount() > 0)
- {
- ### Get the replace vars from the sql results:
- while(list($key, $value) = each($SQL_1->fields))
- {
- $re_this = "%sql1_".$key."%";
- $replace[$re_this] = $value;
+
+ # Get the SQL1/2/3 Query/Arrays
+ foreach (array(1,2,3) as $i)
+ if ($template->fields['sql_'.$i] && $sql1 && ! is_array($sql1)) {
+ # Set our DB prefix
+ $sql = str_replace('%DB_PREFIX%',AGILE_DB_PREFIX,$template->fields['sql_'.$i]);
+
+ # Set the SQL
+ $sql = str_replace('%SQL1%',$db->qstr($sql1),$sql);
+ if ($sql2 && ! is_array($sql2))
+ $sql = str_replace('%SQL2%',$db->qstr($sql2),$sql);
+ if ($sql3 && ! is_array($sql3))
+ $sql = str_replace('%SQL3%',$db->qstr($sql3),$sql);
+
+ $sql .= sprintf(' AND site_id=%s',DEFAULT_SITE);
+
+ $SQL = $db->Execute($sql);
+
+ if (! $SQL) {
+ # Return the error message
+ global $C_debug;
+
+ $C_debug->error(__FILE__,__METHOD__,sprintf('%s %s',$db->ErrorMsg(),$sql));
+
+ } elseif ($SQL->RecordCount() > 0) {
+ # Get the replace vars from the sql results:
+ foreach ($SQL->fields as $key => $value) {
+ $re_this = sprintf('%%sql%s_%s%%',$i,$key);
+ $replace[$re_this] = $value;
+ }
}
}
- }
- elseif (is_array($sql1))
- {
- while(list($key, $value) = each($sql1[$i]))
- $replace[$key] = $value;
- }
- elseif (!empty($sql1))
- {
- $replace['%sql1%'] = $sql3;
+
+ if (is_array($sql1)) {
+ echo '1a.HOW DID I GET HERE??? (WHAT SHOULD THIS DO??)';debug_print_backtrace();die();
+ while(list($key,$value) = each($sql1))
+ $replace[$key] = $value;
+
+ } elseif ($sql1 && ! $template->fields['sql_1']) {
+ $replace['%sql1%'] = $sql1;
}
+ if (is_array($sql2)) {
+ echo '2a.HOW DID I GET HERE??? (WHAT SHOULD THIS DO??)';debug_print_backtrace();die();
+ while(list($key,$value) = each($sql2))
+ $replace[$key] = $value;
- ############################################################
- ### Get the SQL2 Query/Arrays
- if(!empty($template->fields["sql_2"]) && !empty($sql2) &&!is_array($sql2))
- {
- $sql = eregi_replace('%DB_PREFIX%', AGILE_DB_PREFIX, $template->fields["sql_2"]);
- $sql = eregi_replace('%SQL1%', $db->qstr($sql1), $sql);
- if(!is_array($sql2))
- $sql = eregi_replace('%SQL2%', $db->qstr($sql2), $sql);
- if(!is_array($sql3))
- $sql = eregi_replace('%SQL3%', $db->qstr($sql3), $sql);
- $sql .= " AND site_id = ".$db->qstr(DEFAULT_SITE);
- $SQL_2 = $db->Execute($sql);
- if($SQL_2 == false)
- {
- ### return the error message
- global $C_debug;
- $C_debug->error('email_template.inc.php','send', $db->ErrorMsg() . " " . $sql);
+ } elseif ($sql2 && ! $template->fields['sql_2']) {
+ $replace['%sql2%'] = $sql2;
+ }
+
+ if (is_array($sql3)) {
+ echo '3a.HOW DID I GET HERE??? (WHAT SHOULD THIS DO??)';debug_print_backtrace();die();
+ while(list($key,$value) = each($sql3))
+ $replace[$key] = $value;
+
+ } elseif ($sql3 && ! $template->fields['sql_3']) {
+ $replace['%sql3%'] = $sql3;
+ }
+
+ foreach (array('subject','body_text','body_html') as $i)
+ if (! empty($E[$i])) {
+ # Replace the $replace vars in the body and subject
+ foreach ($replace as $key => $value)
+ $E[$i] = str_replace($key,$value,$E[$i]);
+
+ # Remove any unparsed vars from the body text and html:
+ if (preg_match('/%/',$E[$i]))
+ $E[$i] = preg_replace('/%[a-zA-Z0-9_]{1,}%/','',$E[$i]);
}
- else if($SQL_2->RecordCount() > 0)
- {
- ### Get the replace vars from the sql results:
- while(list($key, $value) = each($SQL_2->fields))
- {
- $re_this = "%sql2_".$key."%";
- $replace[$re_this] = $value;
- }
- }
- }
- elseif (is_array($sql2))
- {
- while(list($key, $value) = each($sql2[$i]))
- $replace[$key] = $value;
- }
- elseif (!empty($sql2))
- {
- $replace['%sql2%'] = $sql2;
- }
+ # Set any attachments (not currently supported)
+ $E['attatchments'] = '';
- ############################################################
- ### Get the SQL3 Query/Arrays
- if(!empty($template->fields["sql_3"]) && !empty($sql3) &&!is_array($sql3))
- {
- $sql = eregi_replace('%DB_PREFIX%', AGILE_DB_PREFIX, $template->fields["sql_3"]);
- $sql = eregi_replace('%SQL1%', $db->qstr($sql1), $sql);
- if(!is_array($sql2))
- $sql = eregi_replace('%SQL2%', $db->qstr($sql2), $sql);
- if(!is_array($sql3))
- $sql = eregi_replace('%SQL3%', $db->qstr($sql3), $sql);
- $sql .= " AND site_id = ".$db->qstr(DEFAULT_SITE);
- $SQL_3 = $db->Execute($sql);
- if($SQL_3 == false)
- {
- ### return the error message
- global $C_debug;
- $C_debug->error('email_template.inc.php','send', $db->ErrorMsg() . " " . $sql);
- }
- else if($SQL_3->RecordCount() > 0)
- {
- ### Get the replace vars from the sql results:
- while(list($key, $value) = each($SQL_3->fields))
- {
- $re_this = "%sql3_".$key."%";
- $replace[$re_this] = $value;
- }
- }
- }
- elseif (is_array($sql3))
- {
- while(list($key, $value) = each($sql3))
- $replace[$key] = $value;
- }
- elseif (!empty($sql3))
- {
- $replace['%sql3%'] = $sql3;
- }
-
- ### Replace the $replace vars in the body and subject
- while(list($key, $value) = each($replace))
- {
- $E['subject'] = eregi_replace($key, $value, $E['subject']);
- $E['body_text'] = eregi_replace($key, $value, $E['body_text']);
- if(!empty($E['body_html']))
- $E['body_html'] = eregi_replace($key, $value, $E['body_html']);
- }
-
- ### Remove any unparsed vars from the body text and html:
- if(!empty($E['body_html']) && ereg('%',$E['body_html']))
- @$E['body_html'] = ereg_replace("%[a-zA-Z0-9_]{1,}%", '', $E['body_html']);
- if(!empty($E['body_text']) && ereg("%",$E['body_text']))
- @$E['body_text'] = ereg_replace("%[a-zA-Z0-9_]{1,}%", '', $E['body_text']);
-
- ### Set any attachments (not currently supported)
- $E['attatchments'] = '';
-
- /* email log? */
- global $C_list;
- if(is_object($C_list) && $C_list->is_installed('email_log')) {
+ # Email log?
+ if ($C_list->is_installed('email_log')) {
include_once(PATH_MODULES.'email_log/email_log.inc.php');
- $log = new email_log;
- $log->add($acct, $E['subject'], $E['body_text'], $E['to_email'], false, $E['priority']);
+ $log = new email_log;
+
+ $log->add($acct,$E['subject'],$E['body_text'],$E['to_email'],false,$E['priority']);
}
- ### Call the mail class
- require_once(PATH_CORE . 'email.inc.php');
+ # Call the mail class
+ require_once(PATH_CORE.'email.inc.php');
$email = new CORE_email;
- $email->debug=$this->debug;
- if($type == 0)
- return $email->PHP_Mail($E);
+
+ if ($setup_email->fields['type'] == 1)
+ return $email->SMTP_Mail($E);
else
- return $email->SMTP_Mail($E);
+ return $email->PHP_Mail($E);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/email_template/email_template_construct.xml b/modules/email_template/email_template_construct.xml
index dd5f4db6..4234cafb 100644
--- a/modules/email_template/email_template_construct.xml
+++ b/modules/email_template/email_template_construct.xml
@@ -1,74 +1,118 @@
-
- email_template
-
-
-
-
-
- 0
-
- name
-
- 25
-
-
- name
-
-
-
-
- I8
- 1
- 1
-
-
- I4
- 1
-
-
- I4
- setup_email
- name
- 1
-
-
- C(128)
- 4
- 128
- any
-
-
- L
-
-
- X2
-
-
- X2
-
-
- X2
-
-
- X2
-
-
- X2
-
-
- L
-
-
-
-
- id,site_id,setup_email_id,name,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
- id,site_id,setup_email_id,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
- id,site_id,setup_email_id,name,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
- id,site_id,setup_email_id,name,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
- id,site_id,setup_email_id,name,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
-
-
- 0
+
+ email_template
+
+
+
+
+
+ 0
+
+ name
+
+ 25
+
+ 0
+
+
+
+ name
+
+
+
+
+
+
+ 1
+ I8
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ Active
+ L
+
+
+ setup_email
+ name
+ Setup Email
+ 1
+ I4
+
+
+ Name
+ C(128)
+ 4
+ 128
+ any
+
+
+ Priority
+ L
+
+
+ X2
+
+
+ Notes
+ X2
+
+
+ SQL 1
+ X2
+
+
+ SQL 2
+ X2
+
+
+ SQL 3
+ X2
+
+
+
+
+
+ id,site_id,setup_email_id,name,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
+ id,site_id,setup_email_id,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
+ id,site_id,setup_email_id,name,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
+ id,site_id,setup_email_id,name,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
+ id,site_id,setup_email_id,name,priority,shortcuts,notes,sql_1,sql_2,sql_3,status
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ name
+
+
+ priority
+ bool
+
+
+ status
+ bool_icon
+ 20px
+
+
+
diff --git a/modules/email_template/email_template_install.xml b/modules/email_template/email_template_install.xml
index 31562720..3151fd6b 100644
--- a/modules/email_template/email_template_install.xml
+++ b/modules/email_template/email_template_install.xml
@@ -1,35 +1,55 @@
+
+
- email_template
- setup
-
+
+
+
+
+
1
+
+ email_template
+
+
+
+ setup
+
+
+
+ base
-
-
-
- search
-
-
- view
-
-
- 1
-
-
- search_show
-
-
- add
-
- 1
-
-
- delete
-
-
- update
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/email_template/email_template_install_data.xml b/modules/email_template/email_template_install_data.xml
index a07bde69..c33bcf5d 100644
--- a/modules/email_template/email_template_install_data.xml
+++ b/modules/email_template/email_template_install_data.xml
@@ -481,116 +481,6 @@
SELECT * FROM %DB_PREFIX%voip_vm WHERE mailbox=%SQL3%
1
-
- 658
- 1
- 3
- ticket_piping_add_user
- 0
- This e-mail is set to the user when a e-mail message is successfully piped to a new ticket.
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- 1
-
-
- 659
- 1
- 3
- ticket_piping_add_user_pending
- 0
- This e-mail is set to the user when a e-mail message is piped to a new ticket and requires further authorization...
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- 1
-
-
- 660
- 1
- 3
- ticket_piping_add_user_unauth
- 0
- This e-mail is set to the user when a e-mail message is piped to a new ticket and requires further authorization...
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- 1
-
-
- 661
- 1
- 1
- ticket_staff_add
- 0
- all
- This template is sent to all applicable staff members (except the staff member who added the ticket) when a staff member adds a new ticket
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- SELECT * FROM %DB_PREFIX%ticket_department WHERE id = %SQL2%
- 1
-
-
- 662
- 1
- 1
- ticket_staff_add_user
- 0
- all
- This template is sent to the user when a staff member adds a new ticket to their account
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- 1
-
-
- 663
- 1
- 1
- ticket_staff_update_user
- 0
- all
- This template is sent out to the user when a staff member updates one of their tickets...
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- 1
-
-
- 664
- 1
- 1
- ticket_user_add
- 0
- all
- This template is sent out when a new ticket is added
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- 1
-
-
- 665
- 1
- 1
- ticket_user_add_staff
- 0
- all
- This email is sent to all ticket staff members who are set to recieve new ticket notices
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- SELECT * FROM %DB_PREFIX%ticket_department WHERE id = %SQL2%
- 1
-
-
- 666
- 1
- 1
- ticket_user_update
- 0
- All
- This is sent to the user when they respond to a ticket
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- 1
-
-
- 667
- 1
- 1
- ticket_user_update_staff
- 0
- all
- This email is sent to all ticket staff members who are set to recieve updated ticket notices
- SELECT * FROM %DB_PREFIX%ticket WHERE id = %SQL1%
- SELECT * FROM %DB_PREFIX%ticket_department WHERE id = %SQL2%
- 1
-
668
1
@@ -608,4 +498,4 @@
668
-
\ No newline at end of file
+
diff --git a/modules/email_template_translate/email_template_translate.inc.php b/modules/email_template_translate/email_template_translate.inc.php
index 47375511..f2935734 100644
--- a/modules/email_template_translate/email_template_translate.inc.php
+++ b/modules/email_template_translate/email_template_translate.inc.php
@@ -1,125 +1,33 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:EmailTemplateTranslation
*/
-
-class email_template_translate
-{
- # Open the constructor for this mod
- function email_template_translate()
- {
- # name of this module:
- $this->module = "email_template_translate";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
+/**
+ * The main AgileBill Email Template Translation Class
+ *
+ * @package AgileBill
+ * @subpackage Module:EmailTemplateTranslation
+ */
+class email_template_translate extends OSB_module {
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/email_template_translate/email_template_translate_construct.xml b/modules/email_template_translate/email_template_translate_construct.xml
index 6a81363a..7bdaaf66 100644
--- a/modules/email_template_translate/email_template_translate_construct.xml
+++ b/modules/email_template_translate/email_template_translate_construct.xml
@@ -1,64 +1,99 @@
+
-
- email_template_translate
-
-
-
- email_template
-
- 0
-
- email_template_id
-
- 25
-
-
- email_template_id
- language_id
-
-
-
-
- I8
- 1
- 1
-
-
- I4
- 1
-
-
- I8
- email_template
- name
-
-
- C(16)
-
-
- C(255)
- 1
- 255
- any
-
-
- X2
- any
- 1
-
-
- X2
- 1
-
-
-
-
- id,site_id,email_template_id,language_id,subject,message_text,message_html
- id,site_id,email_template_id,language_id,subject,message_text,message_html
- id,site_id,email_template_id,language_id,subject,message_text,message_html
- id,site_id,email_template_id,language_id,subject,message_text,message_html
- id,site_id,email_template_id,language_id,subject,message_text,message_html
-
-
- 1
+
+ email_template_translate
+
+
+
+ email_template
+
+ 0
+
+ email_template_id
+
+ 25
+
+ 1
+
+
+
+ email_template_id
+ language_id
+
+
+
+
+
+
+ 1
+ I8
+ 1
+
+
+
+ 1
+ I4
+
+
+ I8
+ email_template
+ name
+
+
+ C(16)
+
+
+ C(255)
+ 1
+ 255
+ any
+
+
+ X2
+ any
+ 1
+
+
+ X2
+ 1
+
+
+
+
+
+ email_template_id,language_id,subject,message_text,message_html
+ id,site_id,email_template_id,language_id,subject,message_text,message_html
+ id,site_id,email_template_id,language_id,subject,message_text,message_html
+ id,site_id,email_template_id,language_id,subject,message_text,message_html
+ id,site_id,email_template_id,language_id,subject,message_text,message_html
+
+
+
+ 1
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ email_template_id
+
+
+ language_id
+
+
+ subject
+
+
+
+
+
diff --git a/modules/email_template_translate/email_template_translate_install.xml b/modules/email_template_translate/email_template_translate_install.xml
index eefc8aca..8c2ad50f 100644
--- a/modules/email_template_translate/email_template_translate_install.xml
+++ b/modules/email_template_translate/email_template_translate_install.xml
@@ -1,34 +1,55 @@
+
+
+
+
+
+
+
+ 0
+
email_template_translate
- email_template
+
+
+ email_template
+
+
+
+ base
-
-
-
- search
-
-
- view
-
-
- add
-
-
-
- delete
-
-
- update
-
-
- search_form
-
-
- search_show
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+ add
+
+
+
+ delete
+
+
+
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/email_template_translate/email_template_translate_install_data.xml b/modules/email_template_translate/email_template_translate_install_data.xml
index 15dd5a92..8a63f30a 100644
--- a/modules/email_template_translate/email_template_translate_install_data.xml
+++ b/modules/email_template_translate/email_template_translate_install_data.xml
@@ -1,229 +1,5 @@
-
- 2
- 1
- 4
- english
- New Ticket ( %var_ticket_subject% )
-
- We have received your new ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following information:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 3
- 1
- 5
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new ticket on %date%, with a priority of %var_ticket_priority% .
-
-==================================================
-%var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id%
-]]>
-
-
- 4
- 1
- 6
- english
- Updated Ticket ( %sql1_subject% )
-
- This e-mail is to let you know we have recieved your response to your ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 5
- 1
- 7
- english
- Updated Ticket ( %sql2_name% ) %sql1_subject%
-
- We have received a reply to a ticket at %date%, with a priority of %sql1_priority%.
-
-==================================================
-%sql1_subject%
-==================================================
-%var_ticket_reply%
-==================================================
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 6
- 1
- 9
- english
- New Ticket (%var_ticket_subject% )
-
-
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If promted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
- Subject: %var_ticket_subject%
- %var_ticket_body%
-
-Thank you,
-%site_name%]]>
-
-
- 7
- 1
- 8
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new staff issued ticket at %date%, with a priority of %var_ticket_priority%.
-
-==================================================
-%var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 8
- 1
- 10
- english
- Ticket Response [ %sql1_subject% ]
-
- This e-mail is to let you know we have responded to a ticket of yours on %date%.
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Subject: %sql1_subject%
-%var_message%
-
- Thank you,
-%site_name%
]]>
-
9
1
@@ -236,7 +12,7 @@ You (or someone who knows your email or username) has recently submitted a passw
If this was you, you can click the link below to change your password.
The link expires in 15 minutes so be sure to do this right away:
-%ssl_url%?_page=account:password_reset&validate=%sql3%
+%ssl_url%?_page=account:user_password_reset&validate=%sql3%
If the link above does not display as a link in your browser, you will need to paste it into the address bar of your browser instead.
@@ -245,7 +21,7 @@ If you did not request a password retrieval at our site, then you can safetly ig
Thank you,
%site_name%
]]>
- Dear %acct_first_name%, You (or someone who knows your email or username) has recently submitted a password retrieval request at our site.
If this was you, you can click the link below to change your password. The link expires in 15 minutes so be sure to do this right away:%ssl_url%?_page=account:password_reset&validate=%sql3%
If the link above does not display as a link in your browser, you will need to paste it into the address bar of your browser instead.
If you did not request a password retrieval at our site, then you can safetly ignore and delete this email.
Thank you, %site_name%
]]>
+ Dear %acct_first_name%, You (or someone who knows your email or username) has recently submitted a password retrieval request at our site.
If this was you, you can click the link below to change your password. The link expires in 15 minutes so be sure to do this right away:%ssl_url%?_page=account:user_password_reset&validate=%sql3%
If the link above does not display as a link in your browser, you will need to paste it into the address bar of your browser instead.
If you did not request a password retrieval at our site, then you can safetly ignore and delete this email.
Thank you, %site_name%
]]>
10
@@ -272,10 +48,10 @@ Thanks!
%site_name%: Verification Required
- Dear %acct_first_name%, We have received your registration, but futher action on your part is requested in order to activate your account.
Please click the link below in order to activate your account: %ssl_url%?_page=account:verify&verify=%sql3%
If the text above does not show up as a clickable link, you can paste it to the address bar of your web browser. If you are not sure how to do this, or it does not work, then do the following:
Go to %ssl_url%
Click 'Verify Account'
Enter the following code into the verification form:
%sql3%
Thank you! %site_name%
]]>
+ Dear %acct_first_name%, We have received your registration, but further action on your part is requested in order to activate your account.
Please click the link below in order to activate your account: %ssl_url%?_page=account:user_verify&verify=%sql3%
If the text above does not show up as a clickable link, you can paste it to the address bar of your web browser. If you are not sure how to do this, or it does not work, then do the following:
Go to %ssl_url%
Click 'Verify Account'
Enter the following code into the verification form:
%sql3%
Thank you! %site_name%
]]>
12
@@ -304,7 +80,7 @@ One of our staff members has just added your account to our system.
The username assigned to your account is: %acct_username%
For security reasons, you must choose your own password here:
-%ssl_url%?_page=account:password
+%ssl_url%?_page=account:user_password
Once you set your password, you will be able to login to your account.
@@ -314,7 +90,7 @@ Thank you,
Dear %acct_first_name%,
One of our staff members has just added your account to our system.
The username assigned to your account is: %acct_username%
-For security reasons, you must choose your own password here: %ssl_url%?_page=account:password
+For security reasons, you must choose your own password here: %ssl_url%?_page=account:user_password
Once you set your password, you will be able to login to your account.
Thank you, %site_name%
]]>
@@ -329,18 +105,18 @@ Thank you,
One of our staff members has just added your account to our system. Futher action on your part is required to validate your account.
To validate your account, please click the link below:
-%ssl_url%?_page=account:verify&verify=%sql3%
+%ssl_url%?_page=account:user_verify&verify=%sql3%
The username assigned to your account is: %acct_username%
For security reasons, you must choose your own password here:
-%ssl_url%?_page=account:password
+%ssl_url%?_page=account:user_password
Once you set your password and verify your account, you will be able to login to your account.
Thank you,
%site_name%]]>
- Dear %acct_first_name%, One of our staff members has just added your account to our system. Futher action on your part is required to validate your account.
To validate your account, please click the link below:%ssl_url%?_page=account:verify&verify=%sql3%
The username assigned to your account is: %acct_username%
For security reasons, you must choose your own password here:%ssl_url%?_page=account:password
Once you set your password and verify your account, you will be able to login to your account.
Thank you,%site_name%
]]>
+ Dear %acct_first_name%, One of our staff members has just added your account to our system. Futher action on your part is required to validate your account.
To validate your account, please click the link below:%ssl_url%?_page=account:user_verify&verify=%sql3%
The username assigned to your account is: %acct_username%
For security reasons, you must choose your own password here:%ssl_url%?_page=account:user_password
Once you set your password and verify your account, you will be able to login to your account.
Thank you,%site_name%
]]>
14
@@ -353,13 +129,13 @@ Thank you,
We are sending you this e-mail because you indicated to our staff that you would like to change your account password.
If you would like to change your password, just click this link:
-%ssl_url%?_page=account:password
+%ssl_url%?_page=account:user_password
You can then enter either your username or e-mail address, and we will send you a link where you can change your password.
Thank you,
%site_name%
- Dear %acct_first_name%, We are sending you this e-mail because you indicated to our staff that you would like to change your account password.
If you would like to change your password, just click this link: %ssl_url%?_page=account:password
You can then enter either your username or e-mail address, and we will send you a link where you can change your password.
Thank you,%site_name%
]]>
+ Dear %acct_first_name%, We are sending you this e-mail because you indicated to our staff that you would like to change your account password.
If you would like to change your password, just click this link: %ssl_url%?_page=account:user_password
You can then enter either your username or e-mail address, and we will send you a link where you can change your password.
Thank you,%site_name%
]]>
15
@@ -880,977 +656,6 @@ View invoice details:
]]>
This e-mail is to notify you that %acct_first_name% %acct_last_name% has requested a change of billing schedule for service id %sql1_id%. Current Billing Schedule: %sql2% Requested Billing Schedule: %sql3%
View service details | View account details | View invoice details
]]>
-
- 104
- 1
- 104
- english
- New Ticket ( %var_ticket_subject% )
-
- We have recently received your email dated %date% with the following subject:
-
-%var_ticket_subject%
-
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%]]>
-
-
- 105
- 1
- 105
- english
- New Ticket Received - Authorization Required
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-Further action on your part is required before we can process your request, for one of two possible reasons:
-
-
-1) The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-2) The e-mail address you sent your request from is not the same as the e-mail address on file in your your account with us.
-
-
-
-
-To
-rectify this situation, please visit the link below and provide your
-login details so we can associate your request with an authorized
-account:
You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
- Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
]]>
-
-
- 106
- 1
- 106
- english
- Unable to Process your e-mail request
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-%url%?_page=ticket:ticket
-
-If no available departments are listed at the link above, please contact customer service with your account details and request details for any additional requirements needed to access our ticket system.
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-
-
-
-
%url%?_page=ticket:ticket
-
-
-If no available departments are listed at the link above, please
-contact customer service with your account details and request details
-for any additional requirements needed to access our ticket system.
-
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
-
]]>
-
-
- 616
- 1
- 616
- english
- New Ticket ( %var_ticket_subject% )
-
- We have recently received your email dated %date% with the following subject:
-
-%var_ticket_subject%
-
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%]]>
-
-
- 617
- 1
- 617
- english
- New Ticket ( %var_ticket_subject% )
-
- We have recently received your email dated %date% with the following subject:
-
-%var_ticket_subject%
-
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%]]>
-
-
- 618
- 1
- 618
- english
- New Ticket ( %var_ticket_subject% )
-
- We have recently received your email dated %date% with the following subject:
-
-%var_ticket_subject%
-
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%]]>
-
-
- 619
- 1
- 619
- english
- New Ticket Received - Authorization Required
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-Further action on your part is required before we can process your request, for one of two possible reasons:
-
-
-1) The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-2) The e-mail address you sent your request from is not the same as the e-mail address on file in your your account with us.
-
-
-
-
-To
-rectify this situation, please visit the link below and provide your
-login details so we can associate your request with an authorized
-account:
You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
- Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
]]>
-
-
- 621
- 1
- 621
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new staff issued ticket at %date%, with a priority of %var_ticket_priority%.
-
-==================================================
-%var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 622
- 1
- 622
- english
- New Ticket (%var_ticket_subject% )
-
-
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If promted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
- Subject: %var_ticket_subject%
- %var_ticket_body%
-
-Thank you,
-%site_name%]]>
-
-
- 623
- 1
- 623
- english
- Ticket Response ( %sql1_subject% )
-
- This e-mail is to let you know we have responded to a ticket of yours on %date%.
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Subject: %sql1_subject%
-%var_message%
-
- Thank you,
-%site_name%
]]>
-
-
- 624
- 1
- 624
- english
- New Ticket ( %var_ticket_subject% )
-
- We have received your new ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following information:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 625
- 1
- 625
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new ticket on %date%, with a priority of %var_ticket_priority% .
-
-==================================================
-%var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id%
-]]>
-
-
- 626
- 1
- 626
- english
- Updated Ticket ( %sql1_subject% )
-
- This e-mail is to let you know we have recieved your response to your ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 627
- 1
- 627
- english
- Updated Ticket ( %sql2_name% ) %sql1_subject%
-
- We have received a reply to a ticket at %date%, with a priority of %sql1_priority%.
-
-==================================================
-%sql1_subject%
-==================================================
-%var_ticket_reply%
-==================================================
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 1620
- 1
- 620
- english
- Unable to Process your e-mail request
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-%url%?_page=ticket:ticket
-
-If no available departments are listed at the link above, please contact customer service with your account details and request details for any additional requirements needed to access our ticket system.
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-
-
-
-
%url%?_page=ticket:ticket
-
-
-If no available departments are listed at the link above, please
-contact customer service with your account details and request details
-for any additional requirements needed to access our ticket system.
-
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
-
]]>
-
-
- 1622
- 1
- 628
- english
- New Ticket ( %var_ticket_subject% )
-
- We have recently received your email dated %date% with the following subject:
-
-%var_ticket_subject%
-
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%]]>
-
-
- 1623
- 1
- 629
- english
- New Ticket Received - Authorization Required
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-Further action on your part is required before we can process your request, for one of two possible reasons:
-
-
-1) The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-2) The e-mail address you sent your request from is not the same as the e-mail address on file in your your account with us.
-
-
-
-
-To
-rectify this situation, please visit the link below and provide your
-login details so we can associate your request with an authorized
-account:
You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
- Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
]]>
-
-
- 1625
- 1
- 631
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new staff issued ticket at %date%, with a priority of %var_ticket_priority%.
-
-==================================================
-%var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 1626
- 1
- 632
- english
- New Ticket (%var_ticket_subject% )
-
-
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If promted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
- Subject: %var_ticket_subject%
- %var_ticket_body%
-
-Thank you,
-%site_name%]]>
-
-
- 1627
- 1
- 633
- english
- Ticket Response ( %sql1_subject% )
-
- This e-mail is to let you know we have responded to a ticket of yours on %date%.
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Subject: %sql1_subject%
-%var_message%
-
- Thank you,
-%site_name%
]]>
-
-
- 1628
- 1
- 634
- english
- New Ticket ( %var_ticket_subject% )
-
- We have received your new ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following information:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 1629
- 1
- 635
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new ticket on %date%, with a priority of %var_ticket_priority% .
-
-==================================================
-%var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id%
-]]>
-
-
- 1630
- 1
- 636
- english
- Updated Ticket ( %sql1_subject% )
-
- This e-mail is to let you know we have recieved your response to your ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 1631
- 1
- 637
- english
- Updated Ticket ( %sql2_name% ) %sql1_subject%
-
- We have received a reply to a ticket at %date%, with a priority of %sql1_priority%.
-
-==================================================
-%sql1_subject%
-==================================================
-%var_ticket_reply%
-==================================================
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 11624
- 1
- 630
- english
- Unable to Process your e-mail request
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-%url%?_page=ticket:ticket
-
-If no available departments are listed at the link above, please contact customer service with your account details and request details for any additional requirements needed to access our ticket system.
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-
-
-
-
%url%?_page=ticket:ticket
-
-
-If no available departments are listed at the link above, please
-contact customer service with your account details and request details
-for any additional requirements needed to access our ticket system.
-
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
-
]]>
-
11626
1
@@ -1928,379 +733,6 @@ Please login at the link below to update it so your service is not suspended.
Thank you,
%site_name%]]>
-
-
- 11629
- 1
- 641
- english
- New Ticket ( %var_ticket_subject% )
-
- We have recently received your email dated %date% with the following subject:
-
-%var_ticket_subject%
-
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%]]>
-
-
- 11630
- 1
- 642
- english
- New Ticket Received - Authorization Required
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-Further action on your part is required before we can process your request, for one of two possible reasons:
-
-
-1) The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-2) The e-mail address you sent your request from is not the same as the e-mail address on file in your your account with us.
-
-
-
-
-To
-rectify this situation, please visit the link below and provide your
-login details so we can associate your request with an authorized
-account:
You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
- Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
]]>
-
-
- 11632
- 1
- 644
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new staff issued ticket at %date%, with a priority of %var_ticket_priority%.
-
-================================================== %sql1_email% - %var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 11633
- 1
- 645
- english
- New Ticket (%var_ticket_subject% )
-
-
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If promted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
- Subject: %var_ticket_subject%
- %var_ticket_body%
-
-Thank you,
-%site_name%]]>
-
-
- 11634
- 1
- 646
- english
- Ticket Response ( %sql1_subject% )
-
- This e-mail is to let you know we have responded to a ticket of yours on %date%.
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Subject: %sql1_subject%
-%var_message%
-
- Thank you,
-%site_name%
]]>
-
-
- 11635
- 1
- 647
- english
- New Ticket ( %var_ticket_subject% )
-
- We have received your new ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following information:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 11636
- 1
- 648
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new ticket on %date%, with a priority of %var_ticket_priority% .
-
-==================================================
-%sql1_email% - %var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id%
-]]>
-
-
- 11637
- 1
- 649
- english
- Updated Ticket ( %sql1_subject% )
-
- This e-mail is to let you know we have recieved your response to your ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 11638
- 1
- 650
- english
- Updated Ticket ( %sql2_name% ) %sql1_subject%
-
- We have received a reply to a ticket at %date%, with a priority of %sql1_priority%.
-
-==================================================%sql1_email% - %sql1_subject%
-==================================================
-%var_ticket_reply%
-==================================================
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 111631
- 1
- 643
- english
- Unable to Process your e-mail request
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-%url%?_page=ticket:ticket
-
-If no available departments are listed at the link above, please contact customer service with your account details and request details for any additional requirements needed to access our ticket system.
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-
-
-
-
%url%?_page=ticket:ticket
-
-
-If no available departments are listed at the link above, please
-contact customer service with your account details and request details
-for any additional requirements needed to access our ticket system.
-
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
-
]]>
111633
@@ -2556,381 +988,6 @@ Thank you,
%site_name%
]]>
-
-
- 111640
- 1
- 658
- english
- New Ticket ( %var_ticket_subject% )
-
- We have recently received your email dated %date% with the following subject:
-
-%var_ticket_subject%
-
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%]]>
-
-
- 111641
- 1
- 659
- english
- New Ticket Received - Authorization Required
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-Further action on your part is required before we can process your request, for one of two possible reasons:
-
-
-1) The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-2) The e-mail address you sent your request from is not the same as the e-mail address on file in your your account with us.
-
-
-
-
-To
-rectify this situation, please visit the link below and provide your
-login details so we can associate your request with an authorized
-account:
You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please enter the following details:
-E-mail: %var_email%
-Key: %var_key%
-
- Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
]]>
-
-
- 111643
- 1
- 661
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new staff issued ticket at %date%, with a priority of %var_ticket_priority%.
-
-==================================================
-%var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 111644
- 1
- 662
- english
- New Ticket (%var_ticket_subject% )
-
-
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If promted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
- Subject: %var_ticket_subject%
- %var_ticket_body%
-
-Thank you,
-%site_name%]]>
-
-
- 111645
- 1
- 663
- english
- Ticket Response ( %sql1_subject% )
-
- This e-mail is to let you know we have responded to a ticket of yours on %date%.
-You can view your ticket here: %url%?_page=ticket:user_view&id=%sql1_id%
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Subject: %sql1_subject%
-%var_message%
-
- Thank you,
-%site_name%
]]>
-
-
- 111646
- 1
- 664
- english
- New Ticket ( %var_ticket_subject% )
-
- We have received your new ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following information:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 111647
- 1
- 665
- english
- New Ticket ( %sql2_name% ) %var_ticket_subject%
-
- We have recieved a new ticket on %date%, with a priority of %var_ticket_priority% .
-
-==================================================
-%var_ticket_subject%
-==================================================
-%var_ticket_body%
-==================================================
-
-%url%admin.php?_page=ticket:view&id=%sql1_id%
-]]>
-
-
- 111648
- 1
- 666
- english
- Updated Ticket ( %sql1_subject% )
-
- This e-mail is to let you know we have recieved your response to your ticket, dated %date%.
-
-You can view your ticket here:
-%url%?_page=ticket:user_view&id=%sql1_id%&email=%var_email%&key=%var_key%
-
-If prompted, please provide the following details:
-E-mail: %var_email%
-Key: %var_key%
-
-Please do not reply to this email, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
-]]>
-
-
- 111649
- 1
- 667
- english
- Updated Ticket ( %sql2_name% ) %sql1_subject%
-
- We have received a reply to a ticket at %date%, with a priority of %sql1_priority%.
-
-==================================================
-%sql1_subject%
-==================================================
-%var_ticket_reply%
-==================================================
-%url%admin.php?_page=ticket:view&id=%sql1_id% ]]>
-
-
- 1111642
- 1
- 660
- english
- Unable to Process your e-mail request
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-%url%?_page=ticket:ticket
-
-If no available departments are listed at the link above, please contact customer service with your account details and request details for any additional requirements needed to access our ticket system.
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-Thank you,
-%site_name%
-
- We have recently received your e-mail dated %date% with the following subject:
-
-%var_ticket_subject%
-
-We regret to inform you that we are unable to process your request for the following reason:
-
-The department you sent your request to requires that you have an account with us and maintain a particular subscription.
-
-
-Please check the link below to see if there are any other departments which your account is authorized to access:
-
-
-
-
-
%url%?_page=ticket:ticket
-
-
-If no available departments are listed at the link above, please
-contact customer service with your account details and request details
-for any additional requirements needed to access our ticket system.
-
-
-Please do not reply to this e-mail, this message was generated automatically and your response will not be seen by our staff.
-
-
-Thank you,
-
-%site_name%
-
-
]]>
1111644
@@ -2966,4 +1023,4 @@ Thank you,
1111644
-
\ No newline at end of file
+
diff --git a/modules/faq/auth.inc.php b/modules/faq/auth.inc.php
index c3151b11..07053e2b 100644
--- a/modules/faq/auth.inc.php
+++ b/modules/faq/auth.inc.php
@@ -1,12 +1,35 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
+ *
+ * @link http://www.agileco.com/
+ * @copyright 2004-2008 Agileco, LLC.
+ * @license http://www.agileco.com/agilebill/license1-4.txt
+ * @author Tony Landis
+ * @package AgileBill
+ * @subpackage Modules:Account
+ */
- ### public methods for this module:
-
- $auth_methods = Array
- (
- Array ('module' => 'faq', 'method' => 'faq_categories'),
- Array ('module' => 'faq', 'method' => 'faq_show'),
- Array ('module' => 'faq', 'method' => 'autofill'),
- Array ('module' => 'faq', 'method' => 'faq_search')
- );
+/**
+ * Public FAQ methods
+ */
+
+$auth_methods = array(
+ array('module'=>'faq','method'=>'faq_categories'),
+ array('module'=>'faq','method'=>'faq_show'),
+ array('module'=>'faq','method'=>'autofill'),
+ array('module'=>'faq','method'=>'faq_search')
+);
?>
diff --git a/modules/faq/faq.inc.php b/modules/faq/faq.inc.php
index 843a2e4d..7271acc6 100644
--- a/modules/faq/faq.inc.php
+++ b/modules/faq/faq.inc.php
@@ -1,55 +1,34 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:FAQ
*/
-
-class faq
-{
-
- # Open the constructor for this mod
- function faq()
- {
- # name of this module:
- $this->module = "faq";
- $this->version = "1.0.0a";
-
- if(!defined('AJAX'))
- {
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
- }
-
-
+/**
+ * The main AgileBill FAQ Class
+ *
+ * @package AgileBill
+ * @subpackage Module:FAQ
+ */
+class faq extends OSB_module {
### autofill for admin 'canned messages' in ticket reply
function autofill($VAR)
{
@@ -198,61 +177,33 @@ class faq
$smarty->assign('faq_category_list', @$smart);
}
+ /**
+ * Add a entry to the database
+ */
+ public function add($VAR) {
+ global $VAR;
+ if (empty($VAR['faq_translate_question']))
+ return false;
+ $q = $VAR['faq_translate_question'];
+ unset($VAR['faq_translate_question']);
+ $a = '';
+ if (isset($VAR['faq_translate_answer'])) {
+ $a = $VAR['faq_translate_answer'];
+ unset($VAR['faq_translate_answer']);
+ }
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $id = $db->add($VAR, $this, $type);
+ $id = parent::add($VAR);
- if($id && !empty($VAR['faq_question']))
- {
- # Insert translation
+ # Insert translation
+ if ($id) {
$db = &DB();
- $idx = $db->GenID(AGILE_DB_PREFIX. 'faq_translate_id');
- $sql = "INSERT INTO ".AGILE_DB_PREFIX."faq_translate
- SET
- site_id = ".DEFAULT_SITE.",
- id = $idx,
- faq_id = $id,
- date_orig = ".time().",
- date_last = ".time().",
- language_id = '".DEFAULT_LANGUAGE."',
- answer = ".$db->qstr( @$VAR['faq_answer'] ).",
- question = ".$db->qstr( @$VAR['faq_question']);
- $db->Execute($sql);
+ $db->Execute(sqlInsert($db,'faq_translate',array('faq_id'=>$id,'date_orig'=>time(),'date_last'=>time(),'language_id'=>DEFAULT_LANGUAGE,'question'=>$q,'answer'=>$a)));
}
}
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
##############################
## DELETE ##
##############################
@@ -268,40 +219,6 @@ class faq
$db->mass_delete($VAR, $this, "");
}
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
function linkalize($text)
{
$text = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2", $text);
diff --git a/modules/faq/faq_construct.xml b/modules/faq/faq_construct.xml
index 23b466e0..a5107c1f 100644
--- a/modules/faq/faq_construct.xml
+++ b/modules/faq/faq_construct.xml
@@ -1,78 +1,116 @@
+
+ faq
+
+
+
+
+
+ 0
+
+ sort_order,date_orig,name
+
+ 25
+
+ 0
-
- faq
+
+
+
-
-
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ date-now
+ Date Updated
+ I8
+
+
+ Category
+ I4
+ faq_category
+ name
+
+
+ Date Start
+ I8
+ date
+
+
+ Date Expire
+ I8
+ date
+
+
+ Sort Order
+ I4
+
+
+ Active
+ L
+
+
+ Name
+ C(255)
+ 1
+ 255
+ any
+ 1
+
+
-
-
+
+
+ faq_category_id,date_orig,sort_order,status,name
+ id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
+ id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
+ id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
+ id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
+
-
- 0
+
+
-
- sort_order,date_orig,name
+
+
+ Add FAQ
+ Search FAQ
+ FAQ
+
-
- 35
-
-
-
-
- I4
- 1
-
-
- I4
-
-
- I4
- faq_category
- name
-
-
- I8
- date-now
-
-
- I8
- date-now
-
-
- I8
- date
-
-
- I8
- date
-
-
- I4
-
-
- L
-
-
- C(255)
- 1
- 255
- any
- 1
-
-
-
-
-
- id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
- id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
- id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
- id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
- id,site_id,faq_category_id,date_orig,date_last,date_start,date_expire,sort_order,status,name
-
-
-
- 0
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ name
+
+
+ faq_category_id
+
+
+
diff --git a/modules/faq/faq_install.xml b/modules/faq/faq_install.xml
index 2c1ee562..4876acf2 100644
--- a/modules/faq/faq_install.xml
+++ b/modules/faq/faq_install.xml
@@ -1,49 +1,61 @@
+
+
+
+
+
+ FAQ
+
+ 1
+
+ faq
+
+
+
+ faq
+
+ faq_category,faq_translate
+
+ base
+
-
-
- faq
- faq
- This module controls the FAQs
- 1
- faq_category,faq_translate
-
-
-
-
-
-
-
- search
- Allow users to view the search form
- %%:search_form
- 1
-
-
- view
- Allow users to view records
-
- 1
-
-
- add
- Allow users to add records
- 1
-
-
- delete
-
-
- update
-
-
- search_form
-
-
- search_show
- Allow users to view the search results
-
-
-
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ Search
+ 1
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
diff --git a/modules/faq_category/auth.inc.php b/modules/faq_category/auth.inc.php
index e44fc43d..aeffe7e3 100644
--- a/modules/faq_category/auth.inc.php
+++ b/modules/faq_category/auth.inc.php
@@ -1,9 +1,32 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
+ *
+ * @link http://www.agileco.com/
+ * @copyright 2004-2008 Agileco, LLC.
+ * @license http://www.agileco.com/agilebill/license1-4.txt
+ * @author Tony Landis
+ * @package AgileBill
+ * @subpackage Modules:Account
+ */
- ### public methods for this module:
-
- $auth_methods = Array
- (
- Array ('module' => 'faq_category', 'method' => 'category_list'),
- );
+/**
+ * Public FAQ Category methods
+ */
+
+$auth_methods = array(
+ array('module'=>'faq_category','method'=>'category_list')
+);
?>
diff --git a/modules/faq_category/faq_category.inc.php b/modules/faq_category/faq_category.inc.php
index 6dac9ccb..0c4b5044 100644
--- a/modules/faq_category/faq_category.inc.php
+++ b/modules/faq_category/faq_category.inc.php
@@ -1,55 +1,37 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Modules:FAQ
*/
-
-class faq_category
-{
-
- # Open the constructor for this mod
- function faq_category_construct()
- {
- # name of this module:
- $this->module = "faq_category";
- $this->version = "1.0.0a";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
+/**
+ * The main AgileBill FAQ Category Class
+ *
+ * @package AgileBill
+ * @subpackage Modules:FAQ
+ */
+class faq_category extends OSB_module {
##############################
## GET AUTH CATEGORIES ##
##############################
-
function category_list($VAR)
{
@@ -112,97 +94,5 @@ class faq_category
return true;
}
}
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $this->faq_category_construct();
-
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $this->faq_category_construct();
-
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $this->faq_category_construct();
-
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $this->faq_category_construct();
-
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $this->faq_category_construct();
-
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $this->faq_category_construct();
-
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $this->faq_category_construct();
-
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/faq_category/faq_category_construct.xml b/modules/faq_category/faq_category_construct.xml
index ba59adc8..4b3b4921 100644
--- a/modules/faq_category/faq_category_construct.xml
+++ b/modules/faq_category/faq_category_construct.xml
@@ -1,69 +1,108 @@
+
+ faq_category
+
+
+
+ faq
+
+ 0
+
+ sort_order,name
+
+ 25
+
+ 1
-
- faq_category
+
+
+
-
-
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+ Groups that can access this category
+ C(255)
+ any
+ array
+
+
+ Name
+ C(128)
+ 1
+ 128
+ any
+ 1
+
+
+ Description
+ X2
+
+
+ Active
+ L
+
+
+ Sort Order
+ I4
+
+
-
- faq
+
+
+ date_orig,group_avail,name,description,status,sort_order
+ id,site_id,date_orig,group_avail,name,description,status,sort_order
+ id,site_id,date_orig,group_avail,name,description,status,sort_order
+ id,site_id,date_orig,group_avail,name,description,status,sort_order
+ id,site_id,date_orig,group_avail,name,description,status,sort_order
+
-
- 0
+
+
-
- sort_order,name
+
+
+ Add FAQ Category
+ FAQ Category
+
-
- 35
-
-
-
-
- I4
- 1
-
-
- I4
-
-
- I8
- date-now
-
-
- C(255)
- any
- array
-
-
- C(128)
- 1
- 128
- any
- 1
-
-
- X2
-
-
- L
-
-
- I4
-
-
-
-
-
- id,site_id,date_orig,group_avail,name,description,status,sort_order
- id,site_id,date_orig,group_avail,name,description,status,sort_order
- id,site_id,date_orig,group_avail,name,description,status,sort_order
- id,site_id,date_orig,group_avail,name,description,status,sort_order
- id,site_id,date_orig,group_avail,name,description,status,sort_order
-
-
-
- 0
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ status
+ bool_icon
+ 20px
+
+
+ name
+
+
+ sort_order
+
+
+
diff --git a/modules/faq_category/faq_category_install.xml b/modules/faq_category/faq_category_install.xml
index cfe5d506..8b115b6e 100644
--- a/modules/faq_category/faq_category_install.xml
+++ b/modules/faq_category/faq_category_install.xml
@@ -1,41 +1,55 @@
+
+
+
+
+
+ FAQ Categories
+
+ 1
+
+ faq_category
+
+
+
+ faq
+
+
+
+ base
+
-
-
- faq_category
- faq
- This module controls the FAQs categories
- 1
-
-
-
-
-
-
-
-
-
- search
-
-
- view
-
- 1
-
-
- add
- 1
-
-
- delete
-
-
- update
-
-
- search_show
-
-
-
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
diff --git a/modules/faq_translate/faq_translate.inc.php b/modules/faq_translate/faq_translate.inc.php
index 16c14a1b..610ebe13 100644
--- a/modules/faq_translate/faq_translate.inc.php
+++ b/modules/faq_translate/faq_translate.inc.php
@@ -1,127 +1,33 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Modules:FAQ
*/
-
-class faq_translate
-{
-
- # Open the constructor for this mod
- function faq_translate()
- {
- # name of this module:
- $this->module = "faq_translate";
- $this->version = "1.0.0a";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
+/**
+ * The main AgileBill FAQ Class
+ *
+ * @package AgileBill
+ * @subpackage Modules:FAQ
+ */
+class faq_translate extends OSB_module {
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/faq_translate/faq_translate_construct.xml b/modules/faq_translate/faq_translate_construct.xml
index 759c4a37..7acf3890 100644
--- a/modules/faq_translate/faq_translate_construct.xml
+++ b/modules/faq_translate/faq_translate_construct.xml
@@ -1,77 +1,105 @@
+
+ faq_translate
+
+
+
+ faq
+
+ 0
+
+ faq_id
+
+ 25
+
+ 0
-
- faq_translate
+
+
+ answer,question
+
-
-
-
-
- faq
-
-
- 0
-
-
- faq_id
-
-
- 35
-
-
-
-
- I4
- 1
- 1
-
-
- I4
-
-
- I8
- date-now
-
-
- I8
- date-now
-
-
- I4
- faq
- name
-
-
- C(16)
-
-
- X2
- 1
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+
+ date-now
+ Date Updated
+ I8
+
+
+ I4
+ faq
+ name
+
+
+ C(16)
+
+
+ X2
+ 1
1
-
-
- X2
- 1
- 255
- any
-
-
+
+
+ X2
+ 1
+ 255
+ any
+
+
-
-
- answer,question
-
-
-
-
- id,site_id,date_orig,date_last,faq_id,language_id,answer,question
- id,site_id,date_orig,date_last,faq_id,language_id,answer,question
- id,site_id,date_orig,date_last,faq_id,language_id,answer,question
- id,site_id,date_orig,date_last,faq_id,language_id,answer,question
- id,site_id,date_orig,date_last,faq_id,language_id,answer,question
-
+
+
+ date_orig,faq_id,language_id,answer,question
+ id,site_id,date_orig,date_last,faq_id,language_id,answer,question
+ id,site_id,date_orig,date_last,faq_id,language_id,answer,question
+ id,site_id,date_orig,date_last,faq_id,language_id,answer,question
+ id,site_id,date_orig,date_last,faq_id,language_id,answer,question
+
-
- 0
+
+
+
+
+
+ Add XXX
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ faq_id
+
+
+ language_id
+
+
+ question
+
+
+
diff --git a/modules/faq_translate/faq_translate_install.xml b/modules/faq_translate/faq_translate_install.xml
index 979c19e9..1607ecf9 100644
--- a/modules/faq_translate/faq_translate_install.xml
+++ b/modules/faq_translate/faq_translate_install.xml
@@ -1,34 +1,51 @@
+
+
+
+
+
+
+
+ 0
+
+ faq_translate
+
+
+
+ faq
+
+
+
+ base
+
-
-
- faq_translate
- faq_translate
- This module controls the FAQs translations
-
-
-
-
-
-
- search
-
-
- view
-
-
- add
-
-
- delete
-
-
- update
-
-
- search_show
-
-
-
+
+
+
+ add
+
+
+
+ delete
+
+
+
+ search
+
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
diff --git a/modules/file/auth.inc.php b/modules/file/auth.inc.php
deleted file mode 100644
index 4b629485..00000000
--- a/modules/file/auth.inc.php
+++ /dev/null
@@ -1,11 +0,0 @@
- 'file', 'method' => 'download'),
- Array ('module' => 'file', 'method' => 'category_list'),
- Array ('module' => 'file', 'method' => 'file_list')
- );
-?>
\ No newline at end of file
diff --git a/modules/file/file.inc.php b/modules/file/file.inc.php
deleted file mode 100644
index 9db7cc76..00000000
--- a/modules/file/file.inc.php
+++ /dev/null
@@ -1,492 +0,0 @@
-
- * @package AgileBill
- * @version 1.4.93
- */
-
-class file
-{
-
- # Open the constructor for this mod
- function file()
- {
- # name of this module:
- $this->module = "file";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
- ##############################
- ## LIST AUTH FILES ##
- ##############################
-
- function file_list($VAR)
- {
- global $smarty;
- if(!isset($VAR['id']))
- {
- global $C_debug;
- $smarty->assign('file_display', false);
- return false;
- }
-
- ### Check if user is auth for the selected category:
- $db = &DB();
- $sql = 'SELECT *
- FROM ' . AGILE_DB_PREFIX . 'file WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- file_category_id = ' . $db->qstr($VAR['id']) . ' AND
- status = ' . $db->qstr('1') .'
- ORDER BY sort_order,date_orig,name';
- $result = $db->Execute($sql);
-
- if($result->RecordCount() == 0)
- {
- $smarty->assign('file_display', false);
- return false;
- }
-
- global $C_auth;
- $ii = 0;
-
- while(!$result->EOF)
- {
- @$arr = unserialize($result->fields['group_avail']);
- $this_show = false;
-
- for($i=0; $iauth_group_by_id($arr[$i]))
- {
- $this_show = true;
- $i=count($arr);
- }
- }
-
- if($this_show)
- {
-
- $start = $result->fields['date_start'];
- $expire= $result->fields['date_expire'];
-
- ### Check that it is not expired
- if (( $start == "0" || $start <= time()+2 ) &&
- ( $expire == "0" || $expire >= time() ) )
- {
- $arr_smarty[] = Array (
- 'id' => $result->fields['id'],
- 'name' => $result->fields['name'],
- 'description' => $result->fields['description'],
- 'size' => $result->fields['type'],
- 'size' => $result->fields['size']
- );
- $ii++;
- }
- }
- $result->MoveNext();
- }
-
-
- if($ii == "0")
- {
- $smarty->assign('file_display', false);
- return false;
- }
- else
- {
- $smarty->assign('file_display', true);
- $smarty->assign('file_results', $arr_smarty);
- return true;
- }
- }
-
-
-
- ##############################
- ## GET AUTH CATEGORIES ##
- ##############################
-
- function category_list($VAR)
- {
- /* check if current session is authorized for any ticket departments..
- and return true/false...
- */
-
- global $smarty;
- $db = &DB();
- $sql = 'SELECT id,name,group_avail FROM ' . AGILE_DB_PREFIX . 'file_category WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- status = ' . $db->qstr('1') .'
- ORDER BY sort_order,name';
- $result = $db->Execute($sql);
-
- if($result->RecordCount() == 0)
- {
- $smarty->assign('file_category_display', false);
- return false;
- }
-
- global $C_auth;
- $ii = 0;
-
- while(!$result->EOF)
- {
- @$arr = unserialize($result->fields['group_avail']);
-
- for($i=0; $iauth_group_by_id($arr[$i]))
- {
- ### Add to the array
- $ii++;
- $arr_smarty[] = Array( 'name' => $result->fields['name'],
- 'id' => $result->fields['id']);
- $i=count($arr);
- }
- }
- $result->MoveNext();
- }
-
- if($ii == "0")
- {
- $smarty->assign('file_category_display', false);
- return false;
- }
- else
- {
- $smarty->assign('file_category_display', true);
- $smarty->assign('file_category_results', $arr_smarty);
- return true;
- }
- }
-
-
-
-
- ##############################
- ## DOWNLOAD ##
- ##############################
- function download($VAR)
- {
- $db = &DB();
- $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'file WHERE
- site_id = ' . DEFAULT_SITE . ' AND
- id = ' . $db->qstr(@$VAR['id']) . ' AND
- status = 1';
- $result = $db->Execute($sql);
-
- if($result->RecordCount() == 1)
- {
- $show = true;
-
- ### Validate start date
- $s = $result->fields['date_start'];
- if($s != '' && $s != 0)
- if($s > time())
- $show = false;
-
- ### Validate expire date
- $e = $result->fields['date_expire'];
- if($e != '' && $e != 0)
- if($e < time())
- $show = false;
-
- ### Validate user group:
- if($show) {
- global $C_auth;
- @$arr = unserialize($result->fields['group_avail']);
- $show = false;
- for($i=0; $iauth_group_by_id($arr[$i])) {
- $show = true;
- break;
- }
- }
- }
-
- ### Get the filetype
- if($show)
- {
- $ft = $result->fields['location_type'];
- if($ft == 0)
- $file = PATH_FILES . 'file_'.$VAR['id'].'.dat';
- elseif ($ft == 1)
- $file = $result->fields['location'];
- elseif ($ft == 2)
- $file = $result->fields['location'];
-
- ### Open the file
- if (@$file=fopen($file, 'r'))
- {
- ### Display the correct headers:
- header ("Content-Type: " . $result->fields['type']);
- header ("Content-Size: " . $result->fields['size']);
- header ("Content-Disposition: inline; filename=" . $result->fields['name']);
- fpassthru($file);
- exit;
- }
- }
- }
- echo 'Sorry, the file does not exist or you are not authorized or your access has expired!';
- }
-
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- global $_FILES, $smarty, $C_debug, $C_translate;
-
- if($VAR['file_location_type'] == '') return false;
-
- $lt = $VAR['file_location_type'];
-
- // UPLOADED FILE FROM LOCAL PC
- if($lt == 0) {
- ### Validate the file upoad:
- if(!isset($_FILES['upload_file']) || $_FILES['upload_file']['size'] <= 0)
- {
- global $C_debug;
- $C_debug->alert('You must go back and enter a file for upload!');
- return;
- }
- $VAR['file_size'] = $_FILES['upload_file']['size'];
- $VAR['file_type'] = $_FILES['upload_file']['type'];
- $VAR['file_name'] = $_FILES['upload_file']['name'];
- }
-
- // ENTERED URL TO FILE
- elseif ($lt == 1) {
- ### Validate the remote file can be opened and is greater than 0K
- $file = $VAR['url_file'];
- if(empty($file) || !$fp = fopen ($file, "r")) {
- # error
- $C_debug->alert( $C_translate->translate('remote_file_err','file','') );
- return;
- } else {
- $VAR['file_location'] = $file;
- $fn = explode("/", $file);
- $count = count($fn)-1;
- $VAR['file_name'] = $fn[$count];
- $headers = stream_get_meta_data($fp);
- $headers = $headers['wrapper_data'];
- for($i=0;$icontent_type($file);
- }
- else
- {
- $C_debug->alert( $C_translate->translate('local_file_err','file','') );
- return;
- }
- }
- else { return false; }
-
- ### Create the record
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $id = $db->add($VAR, $this, $type);
-
- ### Copy the uploaded file, or exit if fail:
- if($lt == 0) {
- if(isset($id) && $id > 0) {
- if(!copy($_FILES['upload_file']['tmp_name'], PATH_FILES . 'file_'.$id.'.dat')) {
- $C_debug->alert( $C_translate->translate('copy_file_err','file','') );
- }
- }
- unlink($_FILES['upload_file']['tmp_name']);
- }
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = &DB();
- $id = $this->table . '_id';
-
- # generate the list of ID's
- $id_list = '';
- $ii=0;
-
- if(isset($VAR["delete_id"]))
- {
- $id = explode(',',$VAR["delete_id"]);
- }
- elseif (isset($VAR["id"]))
- {
- $id = explode(',',$VAR["id"]);
- }
-
- for($i=0; $iqstr($id[$i]) . " ";
- $ii++;
- }
- else
- {
- $id_list .= " OR id = " . $db->qstr($id[$i]) . " ";
- $ii++;
- }
- }
- }
-
- if($ii>0)
- {
- # generate the full query
- $q = "DELETE FROM
- ".AGILE_DB_PREFIX."$this->table
- WHERE
- $id_list
- AND
- site_id = " . DEFAULT_SITE;
- $result = $db->Execute($q);
-
- # error reporting
- if ($result === false) {
- global $C_debug;
- $C_debug->error('file.inc.php','delete', $db->ErrorMsg());
- } else {
- for($i=0; $ivalue["CORE"]["module_name"] = $C_translate->translate('name',$this->module,"");
- $message = $C_translate->translate('alert_delete_ids',"CORE","");
- $C_debug->alert($message);
-
- }
- }
- }
-
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-}
-?>
\ No newline at end of file
diff --git a/modules/file/file_construct.xml b/modules/file/file_construct.xml
deleted file mode 100644
index 2ae86c14..00000000
--- a/modules/file/file_construct.xml
+++ /dev/null
@@ -1,100 +0,0 @@
-
-
-
-
- file
-
-
-
-
-
-
-
-
- 0
-
-
- sort_order
-
-
- 35
-
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- I8
- date-now
-
-
- I8
- date-now
-
-
- I8
- date
-
-
- I8
- date
-
-
- I4
- file_category
- name
- 1
-
-
- C(32)
-
-
- I8
-
-
- C(255)
- 1
- 255
- any
-
-
- X2
-
-
- L
-
-
- C(255)
-
-
- L
-
-
- I4
-
-
- C(255)
- array
- any
-
-
-
-
-
- id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order
- id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order
- id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order
- id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order
- id,site_id,group_avail,date_orig,date_last,date_start,date_expire,file_category_id,type,size,name,description,status,location,location_type,sort_order
-
-
-
- 0
-
diff --git a/modules/file/file_install.xml b/modules/file/file_install.xml
deleted file mode 100644
index cc54a7f5..00000000
--- a/modules/file/file_install.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
- file
- file
- This module allows you to manage your downloadable files and permissions.
- 1
-
- file_category
-
-
-
-
-
-
-
- search
- Allow users to view the search form
- %%:search_form
- 1
-
-
- view
- Allow users to view records
- core:search&module=%%&_escape=1&_next_page_one=view
- 1
-
-
- add
- Allow users to add records
- 1
-
-
- delete
-
-
- update
-
-
- search_form
-
-
- search_show
- Allow users to view the search results
-
-
-
-
\ No newline at end of file
diff --git a/modules/file/file_install_data.xml b/modules/file/file_install_data.xml
deleted file mode 100644
index 5d28dce2..00000000
--- a/modules/file/file_install_data.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
diff --git a/modules/file_category/file_category.inc.php b/modules/file_category/file_category.inc.php
deleted file mode 100644
index 994572ab..00000000
--- a/modules/file_category/file_category.inc.php
+++ /dev/null
@@ -1,123 +0,0 @@
-
- * @package AgileBill
- * @version 1.4.93
- */
-
-class file_category
-{
-
- # Open the constructor for this mod
- function file_category()
- {
- # name of this module:
- $this->module = "file_category";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-}
-?>
\ No newline at end of file
diff --git a/modules/file_category/file_category_construct.xml b/modules/file_category/file_category_construct.xml
deleted file mode 100644
index c4846e10..00000000
--- a/modules/file_category/file_category_construct.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-
-
- file_category
-
-
-
-
-
- file
-
-
- 0
-
-
- sort_order
-
-
- 35
-
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- I8
- date-now
-
-
- C(128)
- 1
- 128
- any
-
-
- X2
-
-
- L
-
-
- C(255)
- any
- array
-
-
- I4
-
-
-
-
-
- id,site_id,date_orig,name,description,status,group_avail,sort_order
- id,site_id,date_orig,name,description,status,group_avail,sort_order
- id,site_id,date_orig,name,description,status,group_avail,sort_order
- id,site_id,date_orig,name,description,status,group_avail,sort_order
- id,site_id,date_orig,name,description,status,group_avail,sort_order
-
-
-
-
-
-
diff --git a/modules/file_category/file_category_install.xml b/modules/file_category/file_category_install.xml
deleted file mode 100644
index 921ef90b..00000000
--- a/modules/file_category/file_category_install.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
- file_category
- file
- This module allows you to manage the categories for your downloadable files.
- 1
- file
-
-
-
-
-
-
-
-
- search
-
-
- view
- Allow users to view records
- core:search&module=%%&_escape=1&_next_page_one=view
- 1
-
-
- add
- Allow users to add records
- 1
-
-
- delete
-
-
- update
-
-
- search_show
- Allow users to view the search results
-
-
-
-
\ No newline at end of file
diff --git a/modules/file_category/file_category_install_data.xml b/modules/file_category/file_category_install_data.xml
deleted file mode 100644
index 49188bce..00000000
--- a/modules/file_category/file_category_install_data.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
- 1
- 1
- 1069748554
- Registered Users
- Only registered users can access this category
- 1
- a:4:{i:0;s:1:"2";i:1;s:1:"3";i:2;s:4:"1001";i:3;s:1:"4";}
- 2
-
-
- 2
- 1
- 1069748586
- All Users
- All users can access these downloads
- 1
- a:4:{i:0;s:1:"2";i:1;s:1:"3";i:2;s:4:"1001";i:3;s:1:"4";}
- 1
-
-
- 2
-
-
\ No newline at end of file
diff --git a/modules/group/group.inc.php b/modules/group/group.inc.php
index 662f8463..be954af5 100644
--- a/modules/group/group.inc.php
+++ b/modules/group/group.inc.php
@@ -1,80 +1,55 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:Group
*/
-
-class group
-{
- # Open the constructor for this mod
- function group()
- {
- # name of this module:
- $this->module = "group";
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
+/**
+ * The main AgileBill Group Class
+ *
+ * @package AgileBill
+ * @subpackage Module:Group
+ */
+class group extends OSB_module {
+ /**
+ * Add a record
+ */
+ public function add($VAR) {
+ $group_id = parent::add($VAR);
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
+ if ($group_id) {
+ # Add the new group to the account_group table:
+ $db = &DB();
+ $result = $db->Execute(sqlInsert($db,'account_group',array('date_orig'=>time(),'group_id'=>$group_id,'account_id'=>SESS_ACCOUNT,'acive'=>1)));
+ if ($result === false) {
+ global $C_debug;
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+ return;
+ }
+ } else
+ return false;
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $group_id = $db->add($VAR, $this, $type);
-
- # add the new group to the account_group table:
- $db = &DB();
- $record_id = $db->GenID(AGILE_DB_PREFIX . 'account_group_id');
- $sql= "INSERT INTO ". AGILE_DB_PREFIX ."account_group SET
- id = ".$db->qstr($record_id).",
- site_id = ".$db->qstr(DEFAULT_SITE).",
- date_orig = ".$db->qstr(time()).",
- date_expire = ".$db->qstr('0').",
- group_id = ".$db->qstr($group_id).",
- account_id = ".$db->qstr(SESS_ACCOUNT).",
- active = ".$db->qstr(1);
- $result = $db->Execute($sql);
- if ($result === false)
- {
- global $C_debug;
- $C_debug->error('list.inc.php','select_groups', $db->ErrorMsg());
- return;
- }
-
- # update the current user's authentication so the newly added group appears
+ # Update the current user's authentication so the newly added group appears
# as available to them
global $C_auth;
$C_auth->auth_update();
@@ -82,248 +57,105 @@ class group
return;
}
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
+ private function isAuthorised($VAR) {
+ # Remove any group ids <= 1001 from the VAR array:
+ global $C_debug,$C_auth;
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- #remove any group ids <= 1001 from the VAR array:
- global $C_debug, $C_auth;
- $id_list = '';
- if(isset($VAR["delete_id"]))
- $id = explode(',',$VAR["delete_id"]);
- elseif (isset($VAR["id"]))
- $id = explode(',',$VAR["id"]);
+ $id = array();
- for($i=0; $i 1001 )
- {
- if($i == 0)
- $id_list .= $id[$i];
- else
- $id_list .= ','.$id[$i];
+ if (isset($VAR['id']))
+ $id = explode(',',$VAR['id']);
+
+ for ($i=0; $i 1001) {
# Check if group allowed:
- if(!$C_auth->auth_group_by_id($id[$i])) {
+ if (! $C_auth->auth_group_by_id($id[$i])) {
$C_debug->alert('The selected group cannot be modified as your account is not authorized for it.');
- return;
- }
- } else {
- $C_debug->alert('The selected group is part of the CORE and cannot be edited.');
- return;
- }
- }
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- global $C_auth;
-
- $this->associated_DELETE[] = Array ('table' => 'account_group', 'field' => 'group_id');
- $this->associated_DELETE[] = Array ('table' => 'group_method', 'field' => 'group_id');
-
- #remove any group ids <= 1001 from the mass delete array:
- global $C_debug;
- $id_list = '';
- if(isset($VAR["delete_id"]))
- $id = explode(',',$VAR["delete_id"]);
- elseif (isset($VAR["id"]))
- $id = explode(',',$VAR["id"]);
-
- for($i=0; $i 1001 )
- {
- if($i == 0)
- $id_list .= $id[$i];
- else
- $id_list .= ','.$id[$i];
-
- # Check if group allowed:
- if(!$C_auth->auth_group_by_id(1001) && !$C_auth->auth_group_by_id($id[$i])) {
- $C_debug->alert('The selected group cannot be modified as your account is not authorized for it.');
- return;
+ return true;
}
} else {
- $C_debug->alert('One or more of the groups selected to be deleted are part of the core and cannot be removed.');
+ $C_debug->alert('The selected group is part of the CORE and cannot be edited or deleted.');
+
+ return true;
}
}
-
- $VAR['id'] = $id_list;
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
}
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
+ /**
+ * Update an entry
+ */
+ public function update($VAR) {
+ if (! $this->isAuthorised($VAR))
+ return parent::update($VAR);
}
- ##############################
- ## SEARCH SHOW ##
- ##############################
+ /**
+ * Delete a record
+ */
+ public function delete($VAR) {
+ $this->associated_DELETE = array();
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
+ array_push($this->associated_DELETE,array('table'=>'account_group','field'=>'group_id'));
+ array_push($this->associated_DELETE,array('table'=>'group_method','field'=>'group_id'));
+ if (! $this->isAuthorised($VAR))
+ return parent::delete($VAR);
+ }
- ##############################
- ## VISUAL LAYOUT ##
- ##############################
- function visual_layout()
- {
-
+ /**
+ * Draw the group layout
+ */
+ public function tpl_visual_layout() {
$class = 'form_field';
- # get the default group
- if(!isset($default)) $default = unserialize(DEFAULT_GROUP);
- for($i=0; $iExecute($sql);
+ $result = $db->Execute(sqlSelect($db,'group','id,name,parent_id','id!=0','parent_id,name'));
- # error handling
- if ($result === false)
- {
+ # Error handling
+ if (! $result) {
global $C_debug;
- $C_debug->error('list.inc.php','select_groups', $db->ErrorMsg());
- }
- # number of results
- if($result->RecordCount() > 0)
- {
- # set the results to an array:
- $arr = $result->GetArray();
-
- # start the list
- $ret = '';
-
- #----------------------
- # start the parent loop
- #----------------------
- $group = 0;
- $arr_count = count($arr);
- for($i=0; $i < $arr_count; $i++)
- {
- $level = 0;
- if($arr[$i]['parent_id'] == $group)
- {
-
- $ret .= ' '. $arr[$i]['name'];
- $ret .= ' edit ';
-
- #----------------------
- # start the child loop
- #----------------------
- $level++;
- $ii_group = $arr[$i]['id'];
- $ii_print = 1;
-
- # count the available childs for this group
- $count_child[$ii_group]=0;
- for($c_child=0; $c_child < $arr_count; $c_child++)
- if($arr[$c_child]['parent_id'] == $ii_group) $count_child[$ii_group]++;
-
- for($ii=0; $ii < $arr_count; $ii++)
- {
- if($arr[$ii]['parent_id'] == $ii_group)
- {
- $ret .= ' |__';
- $ret .= ' '. $arr[$ii]['name'];
- $ret .= ' edit ';
-
- $ii_print++;
-
- #--------------------------
- # start the sub-child loop
- #--------------------------
- $level++;
- $iii_group = $arr[$ii]['id'];
- $iii_print = 0;
- for($iii=0; $iii < $arr_count; $iii++)
- {
- if($arr[$iii]['parent_id'] == $iii_group)
- {
-
- if($count_child[$ii_group] < $ii_print)
- {
- $ret .= ' |__ ';
- }
- else
- {
- $ret .= ' | |__ ';
- }
- $ret .= ' '. $arr[$iii]['name'];
- $ret .= ' edit ';
- $iii_print++;
- }
- }
- $level--;
- #-----------------------
- # end of sub-child loop
- #-----------------------
-
- }
- }
- $level--;
- #-------------------
- # end of child loop
- #-------------------
- }
- }
- }
- else
- {
- return 'No groups available!'; // translate!
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
}
- echo $ret;
+
+ # Number of results
+ if ($result->RecordCount() > 0)
+ echo $this->build_nested_list($result->GetArray(),0,0);
+ else
+ echo _('No groups available!');
}
+ /**
+ * This function will build a nested option list
+ * showing the heirachy of the groups
+ *
+ * @see tpl_visual_layout
+ */
+ private function build_nested_list($arr,$level,$current) {
+ $ret = '';
+ for ($i=0; $i < count($arr); $i++) {
+ if ($arr[$i]['parent_id'] == $current) {
+ if ($level)
+ $ret .= sprintf('%s|__ ',str_repeat(' ',$level));
+
+ $ret .= sprintf(' %s %s ',$arr[$i]['name'],$arr[$i]['id'],_('Edit'));
+ $ret .= $this->build_nested_list($arr,$level+1,$arr[$i]['id']);
+ }
+ }
+
+ return $ret;
+ }
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/group/group_construct.xml b/modules/group/group_construct.xml
index 51dbfd0d..2e0e6455 100644
--- a/modules/group/group_construct.xml
+++ b/modules/group/group_construct.xml
@@ -1,72 +1,103 @@
-
- group
-
-
-
-
-
- 0
-
- parent_id,name
-
- 25
-
-
- date_expire
- status,parent_id,date_start,date_expire
-
-
-
-
- I4
- 1
-
-
- I4
-
-
- I8
- date-now
-
-
- I8
- date-time
-
-
- I8
- date-time
-
-
- I4
-
-
- L
-
-
- L
-
-
- C(128)
- any
- 3
- 64
- 1
-
-
- X2
-
-
-
-
- id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id
- id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id
- id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id
- id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id
- id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id
- id,site_id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id
-
-
- 0
+
+ group
+
+
+
+
+
+ 0
+
+ parent_id,name
+
+ 25
+
+ 0
+
+
+
+ date_expire
+ status,parent_id,date_start,date_expire
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ Date Created
+ I8
+
+
+ I8
+ date-time
+ Date Start
+
+
+ I8
+ date-time
+ Date End
+
+
+ I4
+ Parent
+
+
+
+ Active
+ L
+
+
+ L
+ Group Pricing
+
+
+ C(128)
+ any
+ 3
+ 64
+ 1
+ Name
+
+
+ X2
+ Notes
+
+
+
+
+
+ date_start,date_expire,name,notes,status,pricing,parent_id
+ date_start,date_expire,name,notes,status,pricing,parent_id
+ id
+ id,date_orig,date_start,date_expire,name,notes,status,pricing,parent_id
+ name
+
+
+
+
+
+
+
+ Add Group
+ Groups
+ Group Layout Visualisation
+ Modify Group
+
+
+
+
+
diff --git a/modules/group/group_install.xml b/modules/group/group_install.xml
index 23a1babd..722b1535 100644
--- a/modules/group/group_install.xml
+++ b/modules/group/group_install.xml
@@ -1,40 +1,59 @@
+
+
- group
- account_admin
-
+
+
+
+ Groups
+
1
+
+ group
+
+
+
+ setup
+
+
+
+ core
-
-
-
- visual_layout
-
-
-
- search
-
-
- view
-
-
- 1
-
-
- add
-
- 1
-
-
- delete
-
-
- update
-
-
- search_show
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ 1
+ List
+ search
+
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+ tpl_visual_layout
+
+
+
+
diff --git a/modules/group/group_install_data.xml b/modules/group/group_install_data.xml
index a42c61e4..4d899f38 100644
--- a/modules/group/group_install_data.xml
+++ b/modules/group/group_install_data.xml
@@ -1,51 +1,51 @@
-
- 0
- 1
- 0
- 0
- 0
- 0
- 1
- 1
- All Users
- All unregistered users will have access to this.
-
-
- 2
- 1
- 0
- 0
- 0
- 0
- 1
- 1
- Registered Users
-
-
- 4
- 1
- 0
- 0
- 0
- 2
- 1
- 0
- Staff
-
-
- 1001
- 1
- 0
- 0
- 0
- 2
- 1
- 0
- Root
-
-
- 1016
-
-
\ No newline at end of file
+
+ 0
+ 1
+ 0
+ 0
+ 0
+ 0
+ 1
+ 1
+ All Users
+ All unregistered users will have access to this.
+
+
+ 2
+ 1
+ 0
+ 0
+ 0
+ 0
+ 1
+ 1
+ Registered Users
+
+
+ 4
+ 1
+ 0
+ 0
+ 0
+ 2
+ 1
+ 0
+ Staff
+
+
+ 1001
+ 1
+ 0
+ 0
+ 0
+ 2
+ 1
+ 0
+ Root
+
+
+ 1016
+
+
diff --git a/modules/group_method/group_method_install.xml b/modules/group_method/group_method_install.xml
index 169c5910..0b1f24f4 100644
--- a/modules/group_method/group_method_install.xml
+++ b/modules/group_method/group_method_install.xml
@@ -2,7 +2,9 @@
group_method
group
+ module_method
+ core
@@ -26,4 +28,4 @@
-
\ No newline at end of file
+
diff --git a/modules/host_registrar_plugin/host_registrar_plugin.inc.php b/modules/host_registrar_plugin/host_registrar_plugin.inc.php
index 825755d6..07528e4f 100644
--- a/modules/host_registrar_plugin/host_registrar_plugin.inc.php
+++ b/modules/host_registrar_plugin/host_registrar_plugin.inc.php
@@ -1,102 +1,34 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:HostRegistrarPlugin
*/
-
-class host_registrar_plugin
-{
-
- # Open the constructor for this mod
- function host_registrar_plugin()
- {
- # name of this module:
- $this->module = "host_registrar_plugin";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
+/**
+ * The main AgileBill Host Registrar Plugin Class
+ *
+ * @package AgileBill
+ * @subpackage Module:HostRegistrarPlugin
+ */
+class host_registrar_plugin extends OSB_module {
##############################
## SEARCH ##
##############################
@@ -148,11 +80,9 @@ class host_registrar_plugin
}
}
-
##############################
## SEARCH SHOW ##
##############################
-
function search_show($VAR)
{
@@ -236,4 +166,4 @@ class host_registrar_plugin
$smarty->assign('page_arr', $page_arr);
}
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/host_registrar_plugin/host_registrar_plugin_construct.xml b/modules/host_registrar_plugin/host_registrar_plugin_construct.xml
index 0440d43d..6366dfb2 100644
--- a/modules/host_registrar_plugin/host_registrar_plugin_construct.xml
+++ b/modules/host_registrar_plugin/host_registrar_plugin_construct.xml
@@ -1,59 +1,79 @@
-
- host_registrar_plugin
-
-
-
-
-
- 0
-
- name
-
- 25
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
- 1
-
-
- L
-
-
- C(32)
- 1
- 2
- 32
- any
-
-
- C(32)
- 1
- 2
- 32
- any
-
-
- X2
- array
-
-
-
-
- id,site_id,status,name,file,plugin_data
- id,site_id,status,name,file,plugin_data
- id,site_id,status,name,file,plugin_data
- id,site_id,status,name,file,plugin_data
- id,site_id,status,name,file,plugin_data
-
-
- 0 >
-
\ No newline at end of file
+
+ host_registrar_plugin
+
+
+
+
+
+ 0
+
+ name
+
+ 25
+
+ 1
+
+
+
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ Active
+ L
+
+
+ C(32)
+ 1
+ 2
+ 32
+ any
+
+
+ C(32)
+ 1
+ 2
+ 32
+ any
+
+
+ X2
+ array
+
+
+
+
+
+ status,name,file,plugin_data
+ id,site_id,status,name,file,plugin_data
+ id,site_id,status,name,file,plugin_data
+ id,site_id,status,name,file,plugin_data
+ id,site_id,status,name,file,plugin_data
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/host_registrar_plugin/host_registrar_plugin_install.xml b/modules/host_registrar_plugin/host_registrar_plugin_install.xml
index 8b547bd7..bc49746e 100644
--- a/modules/host_registrar_plugin/host_registrar_plugin_install.xml
+++ b/modules/host_registrar_plugin/host_registrar_plugin_install.xml
@@ -1,35 +1,57 @@
+
+
- host_registrar_plugin
- host_server
-
+
+
+
+ Host Registrar Plugins
+
1
+
+ host_registrar_plugin
+
+
+
+ host_server
+
+
+
+
-
-
-
- add
-
-
- update
-
-
- delete
-
-
- view
-
- 1
-
-
- search
-
-
- search_form
-
-
- search_show
-
-
-
-
\ No newline at end of file
+
+
+
+
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/host_registrar_plugin/host_registrar_plugin_install_data.xml b/modules/host_registrar_plugin/host_registrar_plugin_install_data.xml
index 5c8a3687..91da153e 100644
--- a/modules/host_registrar_plugin/host_registrar_plugin_install_data.xml
+++ b/modules/host_registrar_plugin/host_registrar_plugin_install_data.xml
@@ -1,14 +1,14 @@
-
- 1
- 1
- 1
- manual
- MANUAL
-
-
-
- 2
-
-
\ No newline at end of file
+
+ 1
+ 1
+ 1
+ manual
+ MANUAL
+
+
+
+ 2
+
+
diff --git a/modules/host_server/host_server.inc.php b/modules/host_server/host_server.inc.php
index 9c9f6a29..3bd75d44 100644
--- a/modules/host_server/host_server.inc.php
+++ b/modules/host_server/host_server.inc.php
@@ -1,86 +1,57 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:HostServer
*/
-
-class host_server
-{
- # Open the constructor for this mod
- function host_server()
- {
- # name of this module:
- $this->module = "host_server";
+/**
+ * The main AgileBill Hosting Server Class
+ *
+ * @package AgileBill
+ * @subpackage Module:HostServer
+ */
+class host_server extends OSB_module {
+ # Manual add
+ function host_manual_new($service, $server, $account) { }
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
+ # Manual edit
+ function host_manual_edit($service, $server, $account) { }
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
+ # Manual activate
+ function host_manual_active($service, $server, $account) { }
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
+ # Manual deactivate
+ function host_manual_inactive($service, $server, $account) { }
- # manual add
- function host_manual_new($service, $server, $account)
- {
- }
-
- # manual edit
- function host_manual_edit($service, $server, $account)
- {
- }
-
- # manual activate
- function host_manual_active($service, $server, $account)
- {
- }
-
- # manual deactivate
- function host_manual_inactive($service, $server, $account)
- {
- }
-
- # manual delete
- function host_manual_delete($service, $server, $account)
- {
- }
+ # Manual delete
+ function host_manual_delete($service, $server, $account) { }
# Generate a new login
- function generate_login($service,$account,$max_un_len, $max_pw_len, $shared)
- {
+ function generate_login($service,$account,$max_un_len, $max_pw_len, $shared) {
# define username
- if($service['host_username'] != '')
- {
+ if($service['host_username'] != '') {
$ret['username'] = $service['host_username'];
- } else
- {
- if ($shared == false)
- {
+ } else {
+ if ($shared == false) {
# is username already in use on this server?
$db = &DB();
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'service WHERE
@@ -89,8 +60,7 @@ class host_server
host_username = ' . $db->qstr( $account['username'] ) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
- if ($rs->RecordCount() == 0)
- {
+ if ($rs->RecordCount() == 0) {
$ret['username'] = $account['username'];
} else {
$ret['username'] = $this->generate_login1($max_un_len);
@@ -204,18 +174,13 @@ class host_server
return true;
}
+ /**
+ * Add a record
+ */
+ public function add($VAR) {
+ $VAR['host_server_keycode'] = md5(rand(99,999).microtime());
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $VAR['host_server_keycode'] = md5(rand(99,999) . microtime());
-
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
+ return parent::add($VAR);
}
##############################
@@ -252,60 +217,5 @@ class host_server
$smarty->assign('next_server', false);
}
}
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/host_server/host_server_construct.xml b/modules/host_server/host_server_construct.xml
index a2ad8bd6..80abd5ee 100644
--- a/modules/host_server/host_server_construct.xml
+++ b/modules/host_server/host_server_construct.xml
@@ -1,96 +1,141 @@
-
- host_server
-
-
-
-
-
- 0
-
- name
-
- 25
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- L
-
-
- L
-
-
- C(128)
- 1
- 128
- any
-
-
- C(255)
-
-
- C(128)
- 1
- 128
-
-
- X2
- array
-
-
- I4
-
-
- I4
- host_server
- name
-
-
- L
-
-
- C(32)
-
-
- L
-
-
- X2
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- C(128)
-
-
- C(64)
-
-
-
-
- id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
- id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
- id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
- id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
- id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
-
-
- 0
+
+ host_server
+
+
+
+
+
+ 0
+
+ name
+
+ 25
+
+ 0
+
+
+
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ Active
+ L
+
+
+ L
+
+
+ C(128)
+ 1
+ 128
+ any
+
+
+ C(255)
+
+
+ C(128)
+ 1
+ 128
+
+
+ X2
+ array
+
+
+ I4
+
+
+ I4
+ host_server
+ name
+
+
+ L
+
+
+ C(32)
+
+
+ L
+
+
+ X2
+
+
+ C(128)
+
+
+ C(128)
+
+
+ C(128)
+
+
+ C(128)
+
+
+ C(64)
+
+
+
+
+
+ status,debug,name,notes,provision_plugin,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
+ id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
+ id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
+ id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
+ id,site_id,status,debug,name,notes,provision_plugin,provision_plugin_data,max_accounts,next_host_server_id,name_based,name_based_ip,ip_based,ip_based_ip,ns_ip_secondary,ns_ip_primary,ns_primary,ns_secondary,keycode
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ name
+
+
+ provision_plugin
+
+
+ name_based_ip
+
+
+ max_accounts
+
+
+ status
+ bool_icon
+ 20px
+
+
+
diff --git a/modules/host_server/host_server_install.xml b/modules/host_server/host_server_install.xml
index d44e4a6c..479581c7 100644
--- a/modules/host_server/host_server_install.xml
+++ b/modules/host_server/host_server_install.xml
@@ -1,40 +1,59 @@
+
+
- host_server
- host_server
-
+
+
+
+ Hosting Servers
+
1
+
+ host_server
+
+
+
+
+
host_tld,host_registrar_plugin
+
+
-
-
-
- add
-
- 1
-
-
- update
-
-
- search
-
-
- search_form
-
-
-
- view
-
- 1
-
-
- delete
-
-
- search_show
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/host_tld/host_tld.inc.php b/modules/host_tld/host_tld.inc.php
index 774d3b4c..ef0dde04 100644
--- a/modules/host_tld/host_tld.inc.php
+++ b/modules/host_tld/host_tld.inc.php
@@ -1,25 +1,34 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Module:Domains
*/
-
-class host_tld
-{
+
+/**
+ * The main AgileBill Module Domains Class
+ *
+ * @package AgileBill
+ * @subpackage Module:Domains
+ */
+class host_tld extends OSB_module {
/**
* Get the TLD pricing array
@@ -335,82 +344,5 @@ class host_tld
return;
}
}
-
- function constructor()
- {
- $this->module = "host_tld";
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
- function add($VAR)
- {
- $this->constructor();
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- function view($VAR)
- {
- $this->constructor();
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- function update($VAR)
- {
- $this->constructor();
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- function delete($VAR)
- {
- $this->constructor();
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- function search_form($VAR)
- {
- $this->constructor();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- function search($VAR)
- {
- $this->constructor();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- function search_show($VAR)
- {
- $this->constructor();
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/host_tld/host_tld_construct.xml b/modules/host_tld/host_tld_construct.xml
index 43afd8a4..6d150626 100644
--- a/modules/host_tld/host_tld_construct.xml
+++ b/modules/host_tld/host_tld_construct.xml
@@ -1,84 +1,141 @@
-
- host_tld
-
-
-
-
-
- 0
-
- name
-
- 25
-
-
- status
- name
- auto_search
-
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- L
-
-
- C(128)
- any
-
-
- L
-
-
- C(32)
- 1
- 32
-
-
- X2
- array
-
-
- I4
- host_registrar_plugin
- name
-
-
- X2
- array
-
-
- L
-
-
- I4
- 1
- 2
- numeric
-
-
- X2
- array
-
-
-
-
- id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
- id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
- id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
- id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
- id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
-
-
- 0
+
+ host_tld
+
+
+
+
+
+ 15
+
+ name
+
+ 25
+
+ 0
+
+
+
+ status
+ name
+ auto_search
+
+
+
+
+
+
+ 1
+ I4
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ Date Created
+ I8
+
+
+
+ date-now
+ Date Updated
+ I8
+
+
+
+ Active
+ L
+
+
+ Extension Name
+ C(128)
+ any
+
+
+ Taxable
+ L
+
+
+ Whois Plugin
+ C(32)
+ 1
+ 32
+
+
+ X2
+ array
+
+
+ Registrar Plugin
+ I4
+ host_registrar_plugin
+ name
+
+
+ X2
+ array
+
+
+ Auto Search
+ L
+
+
+ Default Term
+ I4
+ 1
+ 2
+ numeric
+
+
+ X2
+ array
+
+
+
+
+
+ date_orig,status,name,whois_plugin,registrar_plugin_id,auto_search,default_term_new,taxable
+ id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
+ id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
+ id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
+ id,site_id,status,name,whois_plugin,whois_plugin_data,registrar_plugin_id,registrar_plugin_data,auto_search,default_term_new,price_group,taxable
+
+
+
+
+
+
+
+ Add TLD
+
+
+
+
+
+
+ id
+ checkbox
+ 25px
+
+
+ name
+
+
+ status
+ bool_icon
+ 20px
+
+
+ whois_plugin
+
+
+ registrar_plugin_id
+
+
+
diff --git a/modules/host_tld/host_tld_install.xml b/modules/host_tld/host_tld_install.xml
index f8438d95..7ced8540 100644
--- a/modules/host_tld/host_tld_install.xml
+++ b/modules/host_tld/host_tld_install.xml
@@ -1,37 +1,57 @@
+
+
- host_tld
- host_server
-
+
+
+
+ Domain TLD
+
1
+
+ host_tld
+
+
+
+ host_server
+
+
-
-
-
- add
-
- 1
-
-
- update
-
-
- delete
-
-
- view
-
- 1
-
-
- search
-
-
- search_form
-
-
- search_show
-
-
-
-
\ No newline at end of file
+
+
+
+
+ Add
+ 1
+ add
+
+
+
+ delete
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_form
+
+
+
+ search_show
+
+
+
+ update
+
+
+
+ view
+
+
+
+
diff --git a/modules/host_tld/host_tld_install_data.xml b/modules/host_tld/host_tld_install_data.xml
index 0ced9544..cce3e428 100644
--- a/modules/host_tld/host_tld_install_data.xml
+++ b/modules/host_tld/host_tld_install_data.xml
@@ -42,7 +42,49 @@
2
+
+ 4
+ 1
+ 1
+ com.au
+ 1
+ DEFAULT
+
+ 1
+
+ 1
+ 2
+
+
+
+ 5
+ 1
+ 1
+ net.au
+ 1
+ DEFAULT
+
+ 1
+
+ 1
+ 2
+
+
+
+ 6
+ 1
+ 1
+ org.au
+ 1
+ DEFAULT
+
+ 1
+
+ 1
+ 2
+
+
- 3
+ 6
-
\ No newline at end of file
+
diff --git a/modules/htaccess/auth.inc.php b/modules/htaccess/auth.inc.php
deleted file mode 100644
index bdbf26a0..00000000
--- a/modules/htaccess/auth.inc.php
+++ /dev/null
@@ -1,10 +0,0 @@
- 'htaccess', 'method' => 'list_dirs'),
- Array ('module' => 'htaccess', 'method' => 'check_smarty')
- );
-?>
\ No newline at end of file
diff --git a/modules/htaccess/htaccess.inc.php b/modules/htaccess/htaccess.inc.php
deleted file mode 100644
index bcc8106e..00000000
--- a/modules/htaccess/htaccess.inc.php
+++ /dev/null
@@ -1,362 +0,0 @@
-
- * @package AgileBill
- * @version 1.4.93
- */
-
-class htaccess
-{
-
- # Open the constructor for this mod
- function htaccess()
- {
- # name of this module:
- $this->module = "htaccess";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
- ##############################
- ## LIST AUTH HTACCESS URLS ##
- ##############################
-
- function list_dirs($VAR)
- {
- global $smarty, $C_auth;
- $ii = 0;
-
- ### Get a list of htaccess groups:
- $db = &DB();
- $sql = 'SELECT id,group_avail
- FROM ' . AGILE_DB_PREFIX . 'htaccess WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- status = ' . $db->qstr('1');
- $result = $db->Execute($sql);
-
- if($result->RecordCount() == 0)
- {
-
- $smarty->assign('htaccess_display', false);
- return false;
- }
-
- while(!$result->EOF)
- {
- @$arr = unserialize($result->fields['group_avail']);
- $id = $result->fields['id'];
- $this_show = false;
-
- for($i=0; $iauth_group_by_id($arr[$i]))
- {
- $this_show = true;
- $i=count($arr);
- }
- }
-
- if($this_show)
- {
- ### Get each directory and add it to the array:
- $db = &DB();
- $sql = 'SELECT *
- FROM ' . AGILE_DB_PREFIX . 'htaccess_dir WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- htaccess_id = ' . $db->qstr($id) . ' AND
- status = ' . $db->qstr('1');
- $result_dir = $db->Execute($sql);
-
- while(!$result_dir->EOF)
- {
-
- $arr_smarty[] = Array (
- 'id' => $result_dir->fields['id'],
- 'name' => $result_dir->fields['name'],
- 'description' => $result_dir->fields['description'],
- 'url' => $result_dir->fields['url']
- );
- $ii++;
- $result_dir->MoveNext();
- }
- }
- $result->MoveNext();
- }
-
-
-
- if($ii == "0")
- {
- $smarty->assign('htaccess_display', false);
- return false;
- }
- else
- {
- $smarty->assign('htaccess_display', true);
- $smarty->assign('htaccess_results', $arr_smarty);
- return true;
- }
- }
-
-
-
-
-
- ##############################
- ## Smarty Authentication ##
- ##############################
- function check_smarty($VAR)
- {
- global $smarty, $C_translate;
- if($this->check_auth($VAR['_htaccess_id']) )
- {
- if(isset($VAR['_htaccess_dir_id']))
- {
- ## Get the URL for this htaccess area:
- $db = &DB();
- $sql = 'SELECT url FROM ' . AGILE_DB_PREFIX . 'htaccess_dir WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($VAR['_htaccess_dir_id']);
- $result = $db->Execute($sql);
- if($result->RecordCount() > 0)
- $smarty->assign('htaccess_url', $result->fields['url']);
- $smarty->assign('htaccess_auth', "1");
- return true;
- }
- }
-
- $smarty->assign('htaccess_auth', "0");
- return false;
- }
-
-
- ##############################
- ## Check Authentication ##
- ##############################
- function check_auth($id)
- {
- ### Check if user is a member of one of the authorized groups:
- $db = &DB();
- $sql = 'SELECT status,group_avail FROM ' . AGILE_DB_PREFIX . 'htaccess WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($id);
- $result = $db->Execute($sql);
-
- if($result->RecordCount() > 0)
- {
- if ($result->fields['status'] != '1') return false;
- @$arr = unserialize($result->fields['group_avail']);
- global $C_auth;
- for($i=0; $iauth_group_by_id($arr[$i])) return true;
-
- }
-
- return false;
- }
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $id = $db->add($VAR, $this, $type);
-
- if(isset($id) && $id > 0)
- {
- # Create the php index file for the Apache mod_auth_remote module:
- /*
- $GroupArray = '';
- for($i=0; $i 0) $GroupArray .= ',';
- $GroupArray .= $VAR['htaccess_group_avail'][$i];
- }
-
- $data = '';
-
- # add dir:
- $dir = PATH_FILES . 'htaccess_'. $id .'/';
- if(is_dir($dir))
- mkdir($dir, '755');
-
- $file = $dir . 'index.php';
- $fp = fopen($file, "w+");
- fputs($fp, $data);
- fclose($fp);
- */
- }
- }
-
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $result = $db->update($VAR, $this, $type);
-
- if($result)
- {
- $id = $VAR['htaccess_id'];
-
- # Update the php index file for the Apache mod_auth_remote module:
- $GroupArray = '';
- for($i=0; $i 0) $GroupArray .= ',';
- $GroupArray .= $VAR['htaccess_group_avail'][$i];
- }
-
-
- $data = '';
-
- # add dir:
- $dir = PATH_FILES . 'htaccess_'. $id;
- if(!is_dir($dir))
- mkdir($dir, '755');
-
- $file = PATH_FILES . 'htaccess_'. $id . '/index.php';
- $fp = fopen($file, "w+");
- fputs($fp, $data);
- fclose($fp);
- }
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- global $C_debug, $C_translate;
-
- ### Get the array
- if(isset($VAR["delete_id"]))
- $id = explode(',', $VAR["delete_id"]);
- elseif (isset($VAR["id"]))
- $id = explode(',', $VAR["id"]);
-
- ### Load class for deleting sub-dirs.
- include_once ( PATH_MODULES .'htaccess_dir/htaccess_dir.inc.php' );
- $htdir = new htaccess_dir;
-
- ### Loop:
- $db = &DB();
- for($i=0; $i 0 )
- {
- ### Delete the htpasswd record:
- $sql = "DELETE FROM ".AGILE_DB_PREFIX."htaccess WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- id = ".$db->qstr($id[$i]);
- $result = $db->Execute($sql);
-
- if ( $result )
- {
- ### Delete .htaccess file(s) from the sub-directories
- $sql = "SELECT id FROM ".AGILE_DB_PREFIX."htaccess_dir WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- htaccess_id = ".$db->qstr($id[$i]);
- $result = $db->Execute($sql);
- if ($result->RecordCount() > 0 )
- $htdir->delete_one($result->fields['id']);
- }
- }
-
- ### Delete the mod_auth_remote files:
- /*
- unlink(PATH_FILES.'htaccess_'. $id[$i] . '/index.php');
- rmdir(PATH_FILES.'htaccess_'. $id[$i] );
- */
- }
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
-}
-?>
\ No newline at end of file
diff --git a/modules/htaccess/htaccess_construct.xml b/modules/htaccess/htaccess_construct.xml
deleted file mode 100644
index 3749b7dc..00000000
--- a/modules/htaccess/htaccess_construct.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-
- htaccess
-
-
-
-
-
- 0
-
- name
-
- 25
-
-
- date_start
- date_expire
- status
-
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
- 1
-
-
- I8
- date
-
-
- I8
- date
-
-
- C(128)
- 3
- 128
- alphanumeric
- 1
-
-
- X2
-
-
- L
-
-
- X2
- any
- array
-
-
-
-
- id,site_id,date_start,date_expire,name,description,status,group_avail
- id,site_id,date_start,date_expire,name,description,status,group_avail
- id,site_id,date_start,date_expire,name,description,status,group_avail
- id,site_id,date_start,date_expire,name,description,status,group_avail
- id,site_id,date_start,date_expire,name,description,status,group_avail
-
-
- 0
-
diff --git a/modules/htaccess/htaccess_install.xml b/modules/htaccess/htaccess_install.xml
deleted file mode 100644
index c6d37810..00000000
--- a/modules/htaccess/htaccess_install.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
- htaccess
- htaccess
-
- 1
- htaccess_dir,htaccess_exclude
-
-
-
-
- search
-
-
- view
-
-
- 1
-
-
- add
-
- 1
-
-
- delete
-
-
- update
-
-
- search_show
-
-
-
-
-
\ No newline at end of file
diff --git a/modules/htaccess/mod_auth_remote.inc.php b/modules/htaccess/mod_auth_remote.inc.php
deleted file mode 100644
index 1b11c42d..00000000
--- a/modules/htaccess/mod_auth_remote.inc.php
+++ /dev/null
@@ -1,103 +0,0 @@
-
- * @package AgileBill
- * @version 1.4.93
- */
-
-# check that the username/password are both set
-if(empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW']))
-{
- mail('sales@agileco.com', 'htaccess empty', '');
- header_unauth();
-}
-
-
-#check the database for a match
-$pre = AGILE_DB_PREFIX;
-$time = time();
-$db = &DB();
-$q = " SELECT DISTINCT
- {$pre}account.id AS account_id,
- {$pre}account_group.group_id AS group_id
- FROM
- {$pre}account
- INNER JOIN
- {$pre}account_group
- ON
- {$pre}account_group.account_id = {$pre}account.id
- WHERE
- (
- {$pre}account.date_expire IS NULL OR
- {$pre}account.date_expire = 0 OR
- {$pre}account.date_expire > ".$db->qstr($time)."
- )
- AND
- {$pre}account.status = ". $db->qstr(1) . "
- AND
- (
- {$pre}account.password = ". $db->qstr(md5(@$_SERVER['PHP_AUTH_PW'])) . "
- OR
- {$pre}account.password = ". $db->qstr(@$_SERVER['PHP_AUTH_PW']) . "
- )
- AND
- {$pre}account.username = ". $db->qstr(@$_SERVER['PHP_AUTH_USER'] )."
- AND
- {$pre}account.site_id = ". $db->qstr(DEFAULT_SITE ) . "
- AND
- (
- {$pre}account_group.date_start IS NULL OR
- {$pre}account_group.date_start = 0 OR
- {$pre}account_group.date_start < ".$db->qstr($time)."
- )
- AND
- (
- {$pre}account_group.date_expire IS NULL OR
- {$pre}account_group.date_expire = 0 OR
- {$pre}account_group.date_expire > ".$db->qstr($time)."
- )
- AND
- {$pre}account_group.active = ".$db->qstr(1)."
- AND
- {$pre}account_group.site_id = ". $db->qstr( DEFAULT_SITE );
-
-# Check for group permissions:
-$result = $db->Execute($q);
-if($result->RecordCount() > 0) {
- while( !$result->EOF ) {
- for($i=0; $ifields["group_id"])
- header_auth();
- }
- $result->MoveNext();
- }
-}
-
-# Not authorized:
-header_unauth();
-
-
-function header_auth() {
- header('HTTP/1.0 201 Authorized');
- exit;
-}
-
-function header_unauth()
-{
- header('WWW-Authenticate: Basic realm="{$realm}"');
- header('HTTP/1.0 401 Unauthorized');
-}
-?>
\ No newline at end of file
diff --git a/modules/htaccess_dir/htaccess_dir.inc.php b/modules/htaccess_dir/htaccess_dir.inc.php
deleted file mode 100644
index c2b059ed..00000000
--- a/modules/htaccess_dir/htaccess_dir.inc.php
+++ /dev/null
@@ -1,472 +0,0 @@
-
- * @package AgileBill
- * @version 1.4.93
- */
-
-class htaccess_dir
-{
-
- # Open the constructor for this mod
- function htaccess_dir()
- {
- # name of this module:
- $this->module = "htaccess_dir";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
-
- # add extra lines needed in the .htaccess files when added/updated:
- # Example:
- #$this->htaccess_extra = "Options +FollowSymlinks\n";
- $this->htaccess_extra = '';
- }
-
-
-
-
- ##############################
- ## ADD ##
- ##############################
-
- function add($VAR)
- {
- global $C_translate, $C_debug;
- $VAR['htaccess_dir_htaccess'] = '# Error!';
- $this->validated = true;
-
- ### Change the path...
- if ( isset ( $VAR['htaccess_dir_path'] ) && $VAR['htaccess_dir_path'] != '' )
- {
- # trim whitspaces
- $VAR['htaccess_dir_path'] = trim ( $VAR['htaccess_dir_path'] );
-
- # replace all forward slashes with back slashes
- $VAR['htaccess_dir_path'] = ereg_replace('\\\\', '/', $VAR['htaccess_dir_path']);
-
- # add the final trailing slash if missing
- if ( !ereg ('[/]$', $VAR['htaccess_dir_path'] ) )
- $VAR['htaccess_dir_path'] = $VAR['htaccess_dir_path'] . '/';
- }
-
-
- if( isset ( $VAR['htaccess_dir_path'] ) && $VAR['htaccess_dir_path'] != '' )
- {
- ################################################################
- ### VERIFY LOCAL PATH & WRITABILITY!
-
- @$filename = $VAR['htaccess_dir_path'] . '.htaccess';
- @$id = $VAR['htaccess_dir_htaccess_id'];
- $db = &DB();
- $sql = 'SELECT name FROM ' . AGILE_DB_PREFIX . 'htaccess WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($id);
- $result = $db->Execute($sql);
- @$name = $result->fields['name'];
-
- ### Check path
- $path = $VAR['htaccess_dir_path'];
- if ( is_dir ( $path ) )
- {
- ### Check if is writable!
- if ( !is_writable ( $path ) )
- {
- ## Path not writable!
- $this->validated = false;
- $this->val_error[] = array(
- 'field' => 'none',
- 'field_trans' => $C_translate->translate('error', 'core', ""),
- 'error' => $C_translate->translate('path_auth', 'htaccess_dir', ""));
- }
- }
- else
- {
- ### Path broken!
- $this->validated = false;
- $this->val_error[] = array(
- 'field' => 'none',
- 'field_trans' => $C_translate->translate('error', 'core', ""),
- 'error' => $C_translate->translate('path_broke', 'htaccess_dir', ""));
- }
- }
-
-
-
- ####################################################################
- ### If validation was failed, skip the db insert &
- ### set the errors & origonal fields as Smarty objects,
- ### and change the page to be loaded.
- ####################################################################
-
- if(!$this->validated)
- {
- global $smarty;
-
- # set the errors as a Smarty Object
- $smarty->assign('form_validation', $this->val_error);
-
- # set the page to be loaded
- if(!defined("FORCE_PAGE"))
- {
- define('FORCE_PAGE', $VAR['_page_current']);
- }
- return;
- }
-
-
- ####################################################################
- ### Create the record/verify fields
-
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $dir_id = $db->add($VAR, $this, $type);
-
- ####################################################################
- ### Create the .htaccess file
-
- if( isset ( $dir_id ) && $dir_id > 0 )
- {
- ### GENERATE THE EXCLUDE LIST
- $exclude_list = $this->exclude_list();
-
- ### GENERATE THE .HTACCESS FILE
- $nl = "\n";
- $data = $this->htaccess_extra . 'RewriteEngine on' . $nl;
- if(empty($VAR['htaccess_dir_recursive']))
- $data .= 'RewriteRule ^(.*)/.*$ - [L]' . $nl;
- $data .= 'RewriteRule ' . $exclude_list . '$ htaccess_index.php?_HTACCESS_ID='.$id.'&_HTACCESS_DIR_ID='.$dir_id;
-
- ### Update the db record
- $db = &DB();
- $sql = "UPDATE ".AGILE_DB_PREFIX."htaccess_dir SET
- htaccess = " . $db->qstr( $data ) . " WHERE
- id = " . $db->qstr( $dir_id ) . " AND
- site_id = " . $db->qstr( DEFAULT_SITE );
- $result = $db->Execute($sql);
-
- ### WRITE THE LOCAL .HTACCESS FILE
- $fp = fopen($filename, "w+");
- fwrite($fp,$data);
- fclose($fp);
-
- ### WRITE THE htaccess_index.php FILE
- $php_filename = $VAR['htaccess_dir_path'] . 'htaccess_index.php';
- $data = $this->create_php();
- $fp = fopen($php_filename, "w+");
- fwrite($fp,$data);
- fclose($fp);
- }
- }
-
-
-
-
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- global $C_translate, $C_debug;
- $this->validated = true;
-
- ### Change the path...
- if ( isset ( $VAR['htaccess_dir_path'] ) && $VAR['htaccess_dir_path'] != '' )
- {
- # trim whitspaces
- $VAR['htaccess_dir_path'] = trim ( $VAR['htaccess_dir_path'] );
-
- # replace all forward slashes with back slashes
- $VAR['htaccess_dir_path'] = ereg_replace('\\\\', '/', $VAR['htaccess_dir_path']);
-
- # add the final trailing slash if missing
- if ( !ereg ('[/]$', $VAR['htaccess_dir_path'] ) )
- $VAR['htaccess_dir_path'] = $VAR['htaccess_dir_path'] . '/';
- }
-
- ### Change the .htaccess data
- if( isset ( $VAR['htaccess_dir_path'] ) && $VAR['htaccess_dir_path'] != '' )
- {
-
- ################################################################
- ### VERIFY LOCAL PATH & WRITABILITY!
-
- @$filename = $VAR['htaccess_dir_path'] . '.htaccess';
- @$php_filename = $VAR['htaccess_dir_path'] . 'htaccess_index.php';
- @$id = $VAR['htaccess_dir_htaccess_id'];
- $db = &DB();
- $sql = 'SELECT name FROM ' . AGILE_DB_PREFIX . 'htaccess WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
- id = ' . $db->qstr($id);
- $result = $db->Execute($sql);
- @$name = $result->fields['name'];
-
-
- ### Check path
- $path = $VAR['htaccess_dir_path'];
- if ( is_dir ( $path ) )
- {
- ### Check if is writable!
- if ( is_writable ( $path ) )
- {
- ### GENERATE THE EXCLUDE LIST
- $exclude_list = $this->exclude_list();
- $nl = "\n";
-
- /*
- $data = $this->htaccess_extra .
- 'RewriteEngine on' . $nl .
- 'RewriteRule ^(.*)/.*$ - [L]' . $nl .
- 'RewriteRule ' .
- '' . $exclude_list . '$ ' .
- 'htaccess_index.php' .
- '?_HTACCESS_ID='.$id.'&_HTACCESS_DIR_ID='.$VAR["htaccess_dir_id"];
- */
-
- $data = $this->htaccess_extra . 'RewriteEngine on' . $nl;
- if(empty($VAR['htaccess_dir_recursive']))
- $data .= 'RewriteRule ^(.*)/.*$ - [L]' . $nl;
- $data .= 'RewriteRule ' . $exclude_list . '$ htaccess_index.php?_HTACCESS_ID='.$id.'&_HTACCESS_DIR_ID='.$VAR["htaccess_dir_id"];
-
-
- ### Set the .htaccess var for the db
- $VAR['htaccess_dir_htaccess'] = $data;
- }
- else
- {
- ## Path not writable!
- $this->validated = false;
- $this->val_error[] = array(
- 'field' => 'none',
- 'field_trans' => $C_translate->translate('error', 'core', ""),
- 'error' => $C_translate->translate('path_auth', 'htaccess_dir', ""));
- }
- }
- else
- {
- ### Path broken!
- $this->validated = false;
- $this->val_error[] = array(
- 'field' => 'none',
- 'field_trans' => $C_translate->translate('error', 'core', ""),
- 'error' => $C_translate->translate('path_broke', 'htaccess_dir', ""));
- }
- }
-
- ####################################################################
- ### If validation was failed, skip the db insert &
- ### set the errors & origonal fields as Smarty objects,
- ### and change the page to be loaded.
- ####################################################################
-
- if(!$this->validated)
- {
- global $smarty;
-
- # set the errors as a Smarty Object
- $smarty->assign('form_validation', $this->val_error);
-
- # set the page to be loaded
- if(!defined("FORCE_PAGE"))
- {
- define('FORCE_PAGE', $VAR['_page']);
- }
- return;
- }
-
- ### Update the db record
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $dir = $db->update($VAR, $this, $type);
-
- if($dir != false)
- {
- ### UPDATE THE LOCAL .HTACCESS FILE
- $fp = fopen($filename, "w+");
- fwrite($fp,$data);
- fclose($fp);
-
- ### UPDATE THE LOCAL htaccess_index.php
- $data = $this->create_php();
- $fp = fopen($php_filename, "w+");
- fwrite($fp,$data);
- fclose($fp);
- }
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- ### Get the array
- if(isset($VAR["delete_id"]))
- $id = explode(',', $VAR["delete_id"]);
- elseif (isset($VAR["id"]))
- $id = explode(',', $VAR["id"]);
-
- ### Loop:
- for($i=0; $idelete_one($id[$i]);
- }
- }
-
- ##############################
- ## DELETE ONE ##
- ##############################
- function delete_one($id)
- {
- global $C_debug, $C_translate;
-
- if ($id == '') return false;
-
- ### Get the details of this directory record
- $db = &DB();
- $sql = "SELECT * FROM ".AGILE_DB_PREFIX."htaccess_dir WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- id = ".$db->qstr($id);
- $result = $db->Execute($sql);
- $type = $result->fields['type'];
- $path = $result->fields['path'];
-
- if( $result != false )
- {
- ### DELETE THE LOCAL .HTACCESS FILE
- $filename = $result->fields['path'] . '.htaccess';
- if ( @unlink ($filename) === false)
- {
- $C_translate->value['htaccess_dir']['dir'] = $result->fields['path'] . '.htaccess';
- $C_debug->alert($C_translate->translate('remove_fail','htaccess_dir',''));
- }
-
- ### DELETE THE LOCAL HTACCESS_ATILE.PHP FILE
- $filename = $result->fields['path'] . 'htaccess_index.php';
- @unlink ($filename);
- }
-
- ### Delete the Record:
- $db = &DB();
- $sql = "DELETE FROM ".AGILE_DB_PREFIX."htaccess_dir WHERE
- site_id = ".$db->qstr(DEFAULT_SITE)." AND
- id = ".$db->qstr($id);
- $resulta = $db->Execute($sql);
-
- ### Success message
- $C_translate->value['htaccess_dir']['dira'] = $path;
- $C_debug->alert($C_translate->translate('remove_success','htaccess_dir',''));
-
- return true;
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
- function exclude_list()
- {
- global $VAR;
-
- $list = '';
- @$Arr = $VAR['htaccess_dir_exclude'];
- if ( count($Arr) == 0) return '';
-
- $db = &DB();
- $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'htaccess_exclude WHERE
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $result = $db->Execute($sql);
- if($result->RecordCount() == 0) return '';
- while(!$result->EOF)
- {
- $id = $result->fields['id'];
- $ext= $result->fields['extension'];
-
- ### GENERATE THE EXCLUDE LIST
- for ($i=0; $iMoveNext();
- }
-
- if ($list != '') $list = '!(\.+' . $list . ')';
- return $list;
- }
-
-
-
- function create_php()
- {
- $data = '';
- return $data;
- }
-}
-?>
\ No newline at end of file
diff --git a/modules/htaccess_dir/htaccess_dir_construct.xml b/modules/htaccess_dir/htaccess_dir_construct.xml
deleted file mode 100644
index 1cdf9011..00000000
--- a/modules/htaccess_dir/htaccess_dir_construct.xml
+++ /dev/null
@@ -1,114 +0,0 @@
-
-
-
- htaccess_dir
-
-
-
- htaccess
-
- 0
-
- id
-
- 25
-
-
- htaccess_id
- status
-
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- I4
- htaccess
- name
- any
- 1
-
-
- C(128)
- 3
- 128
- any
-
-
- X
-
-
- L
-
-
- L
-
-
- L
-
-
- X
- any
-
-
- C(128)
- 1
- 128
- any
-
-
- C(128)
- 1
- 128
- any
- 1
-
-
- C(128)
- 1
- 128
-
-
- C(128)
- 1
- 128
-
-
- C(128)
- 1
- 128
-
-
- C(128)
- 1
- 128
-
-
- C(16)
- 21
- 1
- 4
-
-
- X
- array
-
-
-
-
- id,site_id,name,description,htaccess,status,type,url,path,ftp_host,ftp_user,ftp_pass,ftp_path,ftp_port,htaccess_id,exclude,recursive
- id,site_id,name,description,htaccess,status,type,url,path,ftp_host,ftp_user,ftp_pass,ftp_path,ftp_port,htaccess_id,exclude,recursive
- id,site_id,name,description,htaccess,status,type,url,path,ftp_host,ftp_user,ftp_pass,ftp_path,ftp_port,htaccess_id,exclude,recursive
- id,site_id,name,description,htaccess,status,type,url,path,ftp_host,ftp_user,ftp_pass,ftp_path,ftp_port,htaccess_id,exclude,recursive
- id,site_id,name,description,htaccess,status,type,url,path,ftp_host,ftp_user,ftp_pass,ftp_path,ftp_port,htaccess_id,exclude,recursive
-
-
- 0
-
diff --git a/modules/htaccess_dir/htaccess_dir_install.xml b/modules/htaccess_dir/htaccess_dir_install.xml
deleted file mode 100644
index 4b4c9d26..00000000
--- a/modules/htaccess_dir/htaccess_dir_install.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
- htaccess_dir
- htaccess
-
- 1
-
-
-
-
- search
-
-
- view
-
- 1
-
-
- add
- 1
-
-
- delete
-
-
- update
-
-
- search_show
-
-
-
-
\ No newline at end of file
diff --git a/modules/htaccess_exclude/htaccess_exclude.inc.php b/modules/htaccess_exclude/htaccess_exclude.inc.php
deleted file mode 100644
index a0f9621a..00000000
--- a/modules/htaccess_exclude/htaccess_exclude.inc.php
+++ /dev/null
@@ -1,126 +0,0 @@
-
- * @package AgileBill
- * @version 1.4.93
- */
-
-class htaccess_exclude
-{
-
- # Open the constructor for this mod
- function htaccess_exclude()
- {
- # name of this module:
- $this->module = "htaccess_exclude";
-
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
-
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
-
- $this->method = $construct["construct"]["method"];
- $this->trigger = $construct["construct"]["trigger"];
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
- }
-
-
-
- ##############################
- ## ADD ##
- ##############################
- function add($VAR)
- {
- $type = "add";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->add($VAR, $this, $type);
- }
-
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
- $type = "view";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->view($VAR, $this, $type);
- }
-
- ##############################
- ## UPDATE ##
- ##############################
- function update($VAR)
- {
- $type = "update";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->update($VAR, $this, $type);
- }
-
- ##############################
- ## DELETE ##
- ##############################
- function delete($VAR)
- {
- $db = new CORE_database;
- $db->mass_delete($VAR, $this, "");
- }
-
- ##############################
- ## SEARCH FORM ##
- ##############################
- function search_form($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_form($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search($VAR, $this, $type);
- }
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- $type = "search";
- $this->method["$type"] = explode(",", $this->method["$type"]);
- $db = new CORE_database;
- $db->search_show($VAR, $this, $type);
- }
-
-}
-?>
\ No newline at end of file
diff --git a/modules/htaccess_exclude/htaccess_exclude_construct.xml b/modules/htaccess_exclude/htaccess_exclude_construct.xml
deleted file mode 100644
index 2b722a9d..00000000
--- a/modules/htaccess_exclude/htaccess_exclude_construct.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
- htaccess_exclude
-
-
-
- htaccess
-
- 0
-
- name
-
- 25
-
-
-
- I4
- 1
- 1
-
-
- I4
- 1
-
-
- C(32)
- 3
- 24
- any
-
-
- C(16)
- 2
- 4
- alphanumeric
-
-
-
-
- id,site_id,name,extension
- id,site_id,name,extension
- id,site_id,name,extension
- id,site_id,name,extension
- id,site_id,name,extension
-
-
- 0
-
diff --git a/modules/htaccess_exclude/htaccess_exclude_install.xml b/modules/htaccess_exclude/htaccess_exclude_install.xml
deleted file mode 100644
index 44007e06..00000000
--- a/modules/htaccess_exclude/htaccess_exclude_install.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
- htaccess_exclude
- htaccess
-
- 1
-
-
-
-
- search
-
-
- view
-
-
- 1
-
-
- add
-
- 1
-
-
- delete
-
-
- update
-
-
- search_show
-
-
-
-
-
\ No newline at end of file
diff --git a/modules/htaccess_exclude/htaccess_exclude_install_data.xml b/modules/htaccess_exclude/htaccess_exclude_install_data.xml
deleted file mode 100644
index d1432102..00000000
--- a/modules/htaccess_exclude/htaccess_exclude_install_data.xml
+++ /dev/null
@@ -1,153 +0,0 @@
-
-
-
- 1
- 1
- PHP
- php
-
-
- 2
- 1
- PHP3
- php3
-
-
- 3
- 1
- PHP4
- php4
-
-
- 4
- 1
- PHPS
- phps
-
-
- 5
- 1
- INC
- inc
-
-
- 6
- 1
- HTML
- html
-
-
- 7
- 1
- HTM
- htm
-
-
- 8
- 1
- JPG
- jpg
-
-
- 9
- 1
- JPEG
- jpeg
-
-
- 10
- 1
- GIF
- gif
-
-
- 11
- 1
- BMP
- bmp
-
-
- 12
- 1
- TIF
- tif
-
-
- 13
- 1
- JAVASCRIPT
- js
-
-
- 14
- 1
- CSS
- css
-
-
- 15
- 1
- PDF
- pdf
-
-
- 16
- 1
- MS WORD
- doc
-
-
- 17
- 1
- MS EXCEL
- xls
-
-
- 18
- 1
- CSV
- csv
-
-
- 19
- 1
- TEXT
- txt
-
-
- 20
- 1
- RICH TEXT
- rtf
-
-
- 21
- 1
- XML
- xml
-
-
- 22
- 1
- ZIP
- zip
-
-
- 23
- 1
- GZIP
- gzip
-
-
- 24
- 1
- TAR.GZ
- gz
-
-
- 30
-
-
- 1
-
-
\ No newline at end of file
diff --git a/modules/import/import.inc.php b/modules/import/import.inc.php
index f0098a62..56566476 100644
--- a/modules/import/import.inc.php
+++ b/modules/import/import.inc.php
@@ -1,301 +1,319 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Modules:Import
*/
-
-class import
-{
- # Open the constructor for this mod
- function import()
- {
- # name of this module:
- $this->module = "import";
+/**
+ * The main AgileBill Import Class
+ *
+ * @package AgileBill
+ * @subpackage Modules:Import
+ */
+class import extends OSB_module {
+ protected $actions = array();
+ /**
+ * Test remote database connectivity
+ */
+ protected function test() {
+ global $C_debug,$VAR;
- # location of the construct XML file:
- $this->xml_construct = PATH_MODULES . "" . $this->module . "/" . $this->module . "_construct.xml";
+ # Connect to the remote DB
+ $dbr = &NewADOConnection($this->type);
+ $dbr->Connect($this->host,$this->user,$this->pass,$this->db);
- # open the construct file for parsing
- $C_xml = new CORE_xml;
- $construct = $C_xml->xml_to_array($this->xml_construct);
+ if (! empty($dbr->_errorMsg))
+ $C_debug->alert(sprintf('Failed: %s',$dbr->_errorMsg));
+ else
+ $this->pre_test();
-
- $this->field = $construct["construct"]["field"];
- $this->table = $construct["construct"]["table"];
- $this->module = $construct["construct"]["module"];
- $this->cache = $construct["construct"]["cache"];
- $this->order_by = $construct["construct"]["order_by"];
- $this->limit = $construct["construct"]["limit"];
+ # Return to main import page
+ printf("",$VAR['plugin']);
}
- ### Store import id
- function import_transaction($plugin, $action, $ab_table, $ab_id, $remote_table, $remote_id, &$db)
- {
- # Check that this record has not already been imported:
- $sql = "SELECT id FROM ".AGILE_DB_PREFIX."import WHERE
- plugin = ".$db->qstr($plugin)." AND
- action = ".$db->qstr($action)." AND
- ab_table = ".$db->qstr($ab_table)." AND
- ab_id = ".$db->qstr($ab_id)." AND
- remote_table= ".$db->qstr($remote_table). " AND
- remote_id = ".$db->qstr($remote_id)." AND
- site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($sql);
+ /**
+ * Record pre-setup tests
+ */
+ protected function pre_test() {
+ global $C_debug,$VAR;
- # check results
- if($rs === false || $rs->RecordCount() > 0) {
+ $C_debug->alert('Marked Done!');
+
+ $db = &DB();
+
+ # Insert the import record
+ $this->import_transaction($this->plugin,$VAR['action'],null,null,null,null,$db);
+
+ # Return to main import page
+ printf("",$VAR['plugin']);
+ }
+
+ # Store import id
+ protected function import_transaction($plugin,$action,$ab_table,$ab_id,$remote_table,$remote_id,&$db) {
+ # Check that this record has not already been imported:
+ $sql = sqlSelect($db,'import','id',
+ sprintf('plugin = %s AND action = %s AND ab_table = %s AND ab_id = %s AND remote_table = %s AND remote_id = %s',
+ $db->qstr($plugin),
+ $db->qstr($action),
+ $db->qstr($ab_table),
+ $db->qstr($ab_id),
+ $db->qstr($remote_table),
+ $db->qstr($remote_id)
+ ));
+ $rs = $db->Execute($sql);
+
+ # Check results
+ if ($rs === false || $rs->RecordCount() > 0) {
$db->FailTrans();
return false;
}
# Insert the record
- $id = $db->GenID(AGILE_DB_PREFIX.'import_id');
- $sql = "INSERT INTO ".AGILE_DB_PREFIX."import SET
- id = $id,
- date_orig = ".time().",
- plugin = ".$db->qstr($plugin).",
- action = ".$db->qstr($action).",
- ab_table = ".$db->qstr($ab_table).",
- ab_id = ".$db->qstr($ab_id).",
- remote_table= ".$db->qstr($remote_table). ",
- remote_id = ".$db->qstr($remote_id).",
- site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($sql);
+ $update = array(
+ 'date_orig'=>time(),
+ 'plugin'=>$plugin,
+ 'action'=>$action,
+ 'ab_table'=>$ab_table,
+ 'ab_id'=>$ab_id,
+ 'remote_table'=>$remote_table,
+ 'remote_id'=>$remote_id);
+
+ $db->Execute(sqlInsert($db,'import',$update));
+
return true;
- }
+ }
-
- ### Do an action for a specific plugin:
- function do_action ($VAR)
- {
+ # Do an action for a specific plugin:
+ public function do_action($VAR) {
# Load the plugin
- if(!is_file($file = PATH_PLUGINS . 'import/'.@$VAR['plugin'].'.php'))
- return false;
-
+ if (! is_file($file = sprintf('%simport/%s.php',PATH_PLUGINS,$VAR['plugin'])))
+ return false;
# New instance
include_once($file);
- $import_plugin = new import_plugin;
+ $import_plugin = new import_plugin;
-
- # Call the required method
- call_user_func (array($import_plugin, @$VAR['action']), $VAR, $import_plugin);
+ # Call the required method
+ call_user_func(array($import_plugin,$VAR['action']),$VAR,$import_plugin);
}
-
- ### Do an action for a specific plugin:
- function undo_action ($VAR)
- {
+ # Do an action for a specific plugin:
+ public function undo_action($VAR) {
$db = &DB();
# Make sure this action is done...
- $sql = "SELECT * FROM ".AGILE_DB_PREFIX."import WHERE
- plugin = ".$db->qstr($VAR['plugin'])." AND
- action = ".$db->qstr($VAR['action'])." AND
- site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($sql);
- if($rs->RecordCount() == 0) {
+ $rs = $db->Execute(sqlSelect($db,'import','ab_table,ab_id',sprintf('plugin=::%s:: AND action=::%s::',$VAR['plugin'],$VAR['action'])));
+
+ if ($rs->RecordCount() == 0) {
echo 'There is nothing to undo!';
+
return;
- }
-
- while(!$rs->EOF)
- {
- $table = $rs->fields['ab_table'];
- $id = $rs->fields['ab_id'];
-
- $q = "DELETE FROM ".AGILE_DB_PREFIX."$table WHERE
- id = $id AND
- site_id = ".DEFAULT_SITE;
- $db->Execute($q);
-
- $rs->MoveNext();
}
- # delete the selected action:
- $sql = "DELETE FROM ".AGILE_DB_PREFIX."import WHERE
- plugin = ".$db->qstr($VAR['plugin'])." AND
- action = ".$db->qstr($VAR['action'])." AND
- site_id = ".DEFAULT_SITE;
- $rs = $db->Execute($sql);
+ while (! $rs->EOF) {
+ if (trim($rs->fields['ab_table']) && trim($rs->fields['ab_id']))
+ $db->Execute(sqlDelete($db,$rs->fields['ab_table'],sprintf('id=%s',$rs->fields['ab_id'])));
+ $rs->MoveNext();
+ }
+
+ # Delete the selected action
+ $db->Execute(sqlDelete($db,'import',sprintf('plugin=::%s:: AND action=::%s::',$VAR['plugin'],$VAR['action'])));
}
+ /**
+ * View import plugins
+ */
+ public function view($VAR) {
+ # Load the plugin
+ if (! is_file($file = sprintf('%simport/%s.php',PATH_PLUGINS,$VAR['plugin'])))
+ return false;
- ##############################
- ## VIEW ##
- ##############################
- function view($VAR)
- {
$db = &DB();
- if(!is_file($file = PATH_PLUGINS . 'import/'.@$VAR['plugin'].'.php'))
- return false;
-
include_once($file);
$import_plugin = new import_plugin;
- # Loop through each action to determine its availibility status
+ # Loop through each action to determine its availibility status
$actions = $import_plugin->actions;
- $done = false;
- for($i=0; $iassign('name', $import_plugin->name);
- $smarty->assign('instructions', $import_plugin->instructions);
- $smarty->assign('import', $actions);
- }
-
-
-
-
- ##############################
- ## SEARCH ##
- ##############################
- function search($VAR)
- {
- ### Read the contents of the /plugins/affiliate directory:
- $count = 0;
- chdir(PATH_PLUGINS . 'import');
- $dir = opendir(PATH_PLUGINS . 'import');
- while ($file_name = readdir($dir)) {
- if($file_name != '..' && $file_name != '.' && !eregi("^_", $file_name) && eregi(".php$", $file_name)) {
- $count++;
+ $actions[$i]['records'] = $rs->RecordCount();
+ $done[$actions[$i]['name']] = true;
+ }
}
}
- # define the DB vars as a Smarty accessible block
+ global $smarty;
+ $smarty->assign('name',$import_plugin->name);
+ $smarty->assign('instructions',$import_plugin->instructions);
+ $smarty->assign('import',$actions);
+ }
+
+ /**
+ * Search for available plugs
+ *
+ * @uses CORE_search
+ */
+ public function search($VAR) {
+ # Read the contents of the directory
+ $count = 0;
+ $dir = opendir(PATH_PLUGINS.'import');
+ while ($file_name = readdir($dir))
+ if (! in_array($file_name,array('.','..')) && ! preg_match('/^_/',$file_name) && preg_match('/.php$/',$file_name))
+ $count++;
+
+ # Define the DB vars as a Smarty accessible block
global $smarty;
# create the search record:
- if($count > 0)
- {
+ if ($count > 0) {
# create the search record
- include_once(PATH_CORE . 'search.inc.php');
+ include_once(PATH_CORE.'search.inc.php');
$search = new CORE_search;
- $arr['module'] = $this->module;
- $arr['sql'] = '';
- $arr['limit'] = '999';
- $arr['order_by']= 'name';
+
+ $arr['module'] = $this->module;
+ $arr['sql'] = '';
+ $arr['limit'] = '999';
+ $arr['order_by'] = 'name';
$arr['results'] = $count;
$search->add($arr);
# define the search id and other parameters for Smarty
- $smarty->assign('search_id', $search->id);
+ $smarty->assign('search_id',$search->id);
- # page:
- $smarty->assign('page', '1');
+ # page
+ $smarty->assign('page','1');
- # limit:
- $smarty->assign('limit', '999');
+ # limit
+ $smarty->assign('limit','999');
- # order_by:
- $smarty->assign('order_by', 'name');
+ # order_by
+ $smarty->assign('order_by','name');
# define the result count
- $smarty->assign('results', $count);
+ $smarty->assign('results',$count);
}
}
-
-
- ##############################
- ## SEARCH SHOW ##
- ##############################
-
- function search_show($VAR)
- {
- ### Read the contents of the /plugins/db_mapping directory:
+ /**
+ * Show search results
+ */
+ public function search_show($VAR) {
+ # Read the contents of the directory
$count = 0;
- chdir(PATH_PLUGINS . 'import');
- $dir = opendir(PATH_PLUGINS . 'import');
+ $dir = opendir(PATH_PLUGINS.'import');
while ($file_name = readdir($dir)) {
- if($file_name != '..' && $file_name != '.' && !eregi("^_", $file_name) && eregi(".php$", $file_name) ) {
- $result[$count]['name'] = eregi_replace('.php', '', $file_name);
- $result[$count]['id'] = $count;
+ if (! in_array($file_name,array('.','..')) && ! preg_match('/^_/',$file_name) && preg_match('/.php$/',$file_name)) {
+ $result[$count]['name'] = preg_replace('/.php$/','',$file_name);
+ $result[$count]['id'] = $count;
$count++;
}
- }
+ }
- $class_name = TRUE;
- for ($i=0; $iassign($this->table, $smart);
- $smarty->assign('page', $VAR['page']);
- $smarty->assign('order', $smarty_order);
- $smarty->assign('sort', $smarty_sort);
- $smarty->assign('limit', $search->limit);
+ $smarty->assign('search_show',$smart);
+ $smarty->assign('page',$VAR['page']);
+ $smarty->assign('order',$smarty_order);
+ $smarty->assign('sort',$smarty_sort);
+ $smarty->assign('limit',$search->limit);
$smarty->assign('search_id',$search->id);
- $smarty->assign('results', $count);
+ $smarty->assign('results',$count);
# total pages
- $smarty->assign('pages', 1);
+ $smarty->assign('pages',1);
# current page
- $smarty->assign('page', 1);
- $page_arr = '';
+ $smarty->assign('page',1);
# page array for menu
- $smarty->assign('page_arr', $page_arr);
- }
+ $smarty->assign('page_arr','');
+ }
+
+ /**
+ * Read a plugin map file, for some default values
+ *
+ * @uses CORE_xml;
+ */
+ protected function read_map() {
+ # If there is a map file, open it
+ $pmap = array();
+
+ if (file_exists($mapfile = sprintf('%simport/%s_map.xml',PATH_PLUGINS,$this->plugin))) {
+ $C_xml = new CORE_xml;
+ $map = $C_xml->xml_to_array($mapfile);
+
+ if (isset($map['map']))
+ foreach ($map['map'] as $index => $details)
+ foreach ($map['map'][$index] as $values) {
+ $a = $values['id'];
+ unset($values['id']);
+ $pmap[$index][$a] = $values;
+ }
+ }
+
+ return $pmap;
+ }
}
-?>
\ No newline at end of file
+?>
diff --git a/modules/import/import_construct.xml b/modules/import/import_construct.xml
index 2717b772..6a688ad8 100644
--- a/modules/import/import_construct.xml
+++ b/modules/import/import_construct.xml
@@ -1,65 +1,90 @@
+
+ import
+
+
+
+
+
+ 0
+
+ plugin
+
+ 25
+
+ 1
-
- import
+
+
+
-
-
+
+
+
+
+ 1
+ I8
+ 1
+
+
+
+ 1
+ I4
+
+
+
+ date-now
+ I8
+
+
+ C(32)
+
+
+ C(32)
+
+
+ C(32)
+
+
+ C(32)
+
+
+ I8
+
+
+ I8
+
+
-
-
+
+
+ id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
+ id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
+ id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
+ id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
+ id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
+
-
- 0
+
+
-
- plugin
+
+
+ Import
+
-
- 35
-
-
-
-
- I8
- 1
-
-
- I4
-
-
- I8
-
-
- C(32)
-
-
- C(32)
-
-
- C(32)
-
-
- C(32)
-
-
- I8
-
-
- I8
-
-
-
-
-
- id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
- id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
- id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
- id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
- id,site_id,date_orig,plugin,local_table,ab_table,remote_id,ab_id
-
-
-
- 0
-
\ No newline at end of file
+
+
+
+
+ none
+ plugin
+ 90px
+
+
+ 10px
+
+
+
+
diff --git a/modules/import/import_install.xml b/modules/import/import_install.xml
index f794caf4..a5ba072a 100644
--- a/modules/import/import_install.xml
+++ b/modules/import/import_install.xml
@@ -1,43 +1,47 @@
+
+
+
+
+
+ Import
+
+ 1
+
+ import
+
+ ]]>
+
+ setup
+
+
+
+ base
+
-
-
- import
- setup
-
- 1
-
-
-
-
-
-
-
-
-
- do_action
-
-
-
- undo_action
-
-
-
-
- view
- core:search&module=%%&_escape=1
-
-
-
- search
- core:search&module=%%&_escape=1
- 1
-
-
- search_show
-
-
-
-
-
\ No newline at end of file
+
+
+
+ List
+ 1
+ search
+
+
+
+
+ search_show
+
+
+
+ view
+
+
+
+ do_action
+
+
+ undo_action
+
+
+
diff --git a/modules/invoice/PDF/pdf_invoice_itemised-fpdf.inc.php b/modules/invoice/PDF/pdf_invoice_itemised-fpdf.inc.php
new file mode 100644
index 00000000..738b4f58
--- /dev/null
+++ b/modules/invoice/PDF/pdf_invoice_itemised-fpdf.inc.php
@@ -0,0 +1,621 @@
+Image($logo,$x,$y,$size);
+ }
+
+ /**
+ * Draw the Company Address
+ */
+ public function drawCompanyAddress($inv) {
+ global $C_translate;
+
+ # Add the company address next to the logo
+ $x = 40; $y = 9;
+
+ $this->SetFont('arial','B',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['NAME']); $y += 4;
+
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['TAXID']); $y += 6;
+
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['ADDRESS']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['site']['CITY'],$inv->print['site']['STATE'],$inv->print['site']['ZIP'])); $y += 4;
+
+ $y += 2;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Phone:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['PHONE']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Fax:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['FAX']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Web:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['URL']); $y += 4;
+ }
+
+ public function drawRemittenceStub($inv) {
+ global $C_translate;
+
+ # Draw the remittance line
+ $this->Line(9,195,200,195);
+
+ $x = 18; $y = 200;
+
+ $this->SetFont('arial','B',13);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_payment_remit','setup_invoice')); $y +=5;
+
+ $this->SetFont('arial','',8);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_return1','setup_invoice')); $y +=3;
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_return2','setup_invoice').' '.$inv->print['site']['NAME']);
+
+ # Due Date
+ $x = 110; $y = 200;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_bill_date','setup_invoice'));
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['date_orig']),0,0,'R');
+
+ # Account ID
+ $y = 205;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_account_number','setup_invoice'));
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->print['account']['id']),0,0,'R');
+
+ # Invoice number
+ $y = 210;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number','setup_invoice'));
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->getInvoiceNum()),0,0,'R');
+
+ # Company Address
+ $y = 216;
+ $this->SetFont('arial','',10);
+ $this->SetXY(18,$y); $this->Cell(0,0,$inv->print['site']['NAME']); $y += 4;
+ $this->SetXY(18,$y); $this->Cell(0,0,$inv->print['site']['ADDRESS']); $y += 4;
+ $this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['site']['CITY'],$inv->print['site']['STATE'],$inv->print['site']['ZIP'])); $y += 4;
+
+ # Previous Due
+ $y = 215;
+ $this->SetFont('arial','',9);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Due');
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()),0,0,'R');
+
+ $y = 219;
+ $this->SetFont('arial','',9);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_amount_due_by','setup_invoice').' '.date(UNIX_DATE_FORMAT,$inv->print['invoice']['due_date']));
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+
+ # Total Due
+ $y = 224;
+ $this->SetFont('arial','B',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Total Due');
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()+$inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+
+ # Draw the Customers Address
+ $x = 25; $y = 248;
+
+ $this->SetFont('arial','B',12);
+
+ if ($this->billToCompany && ! empty($inv->print['account']['company']))
+ $name = $inv->print['account']['company'];
+ else
+ $name = sprintf('%s %s',$inv->print['account']['first_name'],$inv->print['account']['last_name']);
+
+ $this->SetXY($x,$y); $this->Cell(0,0,html_entity_decode($name,ENT_NOQUOTES)); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s %s ',$inv->print['account']['address1'],$inv->print['account']['address2'])); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['account']['city'],$inv->print['account']['state'],$inv->print['account']['zip'])); $y += 5;
+ }
+
+ public function drawInvoiceHeader($inv) {
+ global $C_translate;
+
+ $x = 125; $y = 10;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,35+($inv->print['invoice']['billed_amt'] ? 5 : 0),'',1,0,'',1);
+
+ # Draw a box around the invoice due date and amount due.
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,'TAX INVOICE');
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->getInvoiceNum()),0,0,'R');
+
+ # Invoice number at top of page.
+ $y += 7;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_bill_date','setup_invoice')); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_amount_due_by','setup_invoice'));
+ $this->SetFont('arial','B',11);
+
+ $y -= 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['date_orig']),0,0,'R'); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['due_date']),0,0,'R');
+
+ $y += 5;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Due');
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()),0,0,'R');
+
+ $y += 5;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_current_charges','setup_invoice'));
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']),0,0,'R');
+
+ if ($inv->print['invoice']['billed_amt']) {
+ $y += 5;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Payments Received');
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+
+ $y += 5;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Total Payable');
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()+$inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+
+ #@todo Limit the size of the news to 6 lines
+ public function drawNews($news) {
+ global $C_translate;
+
+ if (! $news)
+ return;
+
+ $x = 9; $y = 170;
+
+ # Draw a box.
+ $this->SetFillColor(243);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,20,'',1,0,'',1);
+
+ $this->SetFont('arial','',8);
+ $this->SetXY($x,$y); $this->MultiCell(0,3,str_replace('\n',"\n",$news),0,'L',0);
+ }
+
+ #@todo make this list dynamic
+ public function drawPaymentMethods($inv) {
+ $x = 110; $y = 242;
+
+ # Draw a box.
+ $this->SetFillColor(235);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,32,'',1,0,'',1);
+
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x,$y); $this->Cell(0,0,'This invoice can also be paid by:'); $y += 4;
+
+ # Direct Debit
+ $logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-dd.png');
+ $this->Image($logo,$x+1,$y,8);
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Credit to our Bank Account'); $y += 3;
+ $this->SetFont('arial','',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'BSB:'); $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'ACCOUNT:'); $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'REF:'); $y += 3;
+
+ $y -= 9;
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x+30,$y); $this->Cell(0,0,'633-000'); $y += 3;
+ $this->SetXY($x+30,$y); $this->Cell(0,0,'120 440 821'); $y += 3;
+ $this->SetXY($x+30,$y); $this->Cell(0,0,$inv->getInvoiceID()); $y += 3;
+
+ # Direct Debit
+ $y += 3;
+ $logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-dd.png');
+ $this->Image($logo,$x+1,$y,8);
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Debit'); $y += 3;
+ $this->SetFont('arial','',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Please visit '.$inv->print['site']['URL']); $y += 3;
+ }
+
+ /**
+ * Draw previous invoices due
+ */
+ public function drawSummaryInvoicesDue($items) {
+ $x = 125; $y = $this->sum_y ? $this->sum_y : 50;
+
+ # Calculate the box size
+ $box = count($items) < $this->itemsPreviousMax ? count($items) : $this->itemsPreviousMax;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,5*(1+$box)+1,'',1,0,'',1);
+
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Invoices due'); $y += 5;
+
+ $this->SetFont('arial','',11);
+ $i = 0;
+ $sum_total = 0;
+ foreach ($items as $line) {
+ if (++$i < $this->itemsPreviousMax) {
+ $this->SetXY($x,$y);
+ $this->Cell(0,0,sprintf('%s #%06s',date(UNIX_DATE_FORMAT,$line['date_orig']),$line['id']));
+ $this->Cell(0,0,$this->_currency($line['total_amt']-$line['billed_amt']),0,0,'R'); $y += 5;
+
+ } else {
+ $sum_total += $line['total_amt']-$line['billed_amt'];
+ }
+ }
+
+ if ($sum_total) {
+ $this->SetXY($x,$y);
+ $this->SetFont('arial','I',11);
+ $this->Cell(0,0,'Other invoices');
+ $this->SetFont('arial','',11);
+ $this->Cell(0,0,$this->_currency($sum_total),0,0,'R'); $y += 5;
+ }
+
+ $this->sum_y = $y+5;
+ }
+
+ /**
+ * Called before begining to loop the invoice_item table. Used to set initial values.
+ */
+ public function drawLineItems_pre($iteration) {
+ $this->iteration = $iteration;
+ if ($iteration>1)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Called once per line item to add to the PDF invoice. This function serves to
+ * direct each iteration to a different function which handles a specific piece
+ * of the PDF building puzzle.
+ */
+ public function drawLineItems($db,$line,$invnum) {
+ switch($this->iteration) {
+ case 0:
+ $this->drawLineItems_0($db,$line,$invnum);
+ break;
+
+ case 1:
+ $this->drawLineItems_1($db,$line,$invnum);
+ break;
+
+ default:
+ echo 'Unknown PDF iteration encountered. Halting.';
+ exit;
+ }
+ }
+
+ /**
+ * Draws the non-VoIP related items for iteration 0.
+ */
+ private function drawLineItems_0($db,$line,$invnum) {
+ global $C_translate;
+
+ if ($line['price_type'] == 0 && $line['item_type']==5)
+ return;
+
+ $x = 10; $y = 5;
+ if ($this->i == 0 || $this->i%51 == 0) {
+ $this->AddPage();
+
+ $this->SetFont('arial','B',12);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_itemized_charges','setup_invoice'));
+ $this->Cell(0,0,$C_translate->translate('pdf_page','setup_invoice').$this->PageNo(),0,0,'R');
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number_small','setup_invoice').$invnum,0,0,'C');
+
+ # Draw table headers
+ $y += 10;
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x,$y);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_description','setup_invoice'));
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_quantity','setup_invoice'));
+ $this->SetX($x+160);
+ $this->Cell(10,0,$C_translate->translate('pdf_item_cost','setup_invoice'),0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_amount','setup_invoice'),0,0,'R');
+ $this->Line($x,$y+2,200,$y+2);
+ $y += 5;
+ $this->SetY($y);
+ }
+
+ $this->SetFont('arial','',8);
+ $this->SetX($x);
+ $this->Cell(0,0,$line['name']);
+
+ if (isset($line['price_base'])) {
+ $this->SetX($x+160);
+ $this->Cell(10,0,$this->_currency($line['price_base']),0,0,'R');
+ }
+
+ if (isset($line['qty'])) {
+ $this->SetX($x+130);
+ $this->Cell(10,0,$line['qty'],0,0,'R');
+ }
+
+ $this->SetX($x+130);
+ $this->Cell(0,0,$this->_currency($line['total_amt']),0,0,'R');
+
+ if ($this->show_service_range && $line['daterange']) {
+ $this->SetFont('arial','I',7);
+ $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Service Period');
+ $this->SetFont('arial','',7);
+ $this->SetXY($x+40,$y); $this->Cell(0,0,$line['daterange']);
+ }
+
+ if ($line['domain']) {
+ $this->SetFont('arial','I',7);
+ $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Domain');
+ $this->SetFont('arial','',7);
+ $this->SetXY($x+40,$y); $this->Cell(0,0,$line['domain']);
+ }
+
+ if ($line['attr']) {
+ $showchars = 20;
+ foreach (explode("\n",$line['attr']) as $attr) {
+ list($field,$value) = explode('==',$attr);
+
+ $this->SetFont('arial','I',7);
+ $this->y += 3;
+ $this->SetXY(20,$this->y); $this->Cell(0,0,strlen($field) > $showchars ? substr($field,0,$showchars-2).'...' : $field);
+ $this->SetFont('arial','',7);
+ $this->SetXY(50,$this->y); $this->Cell(0,0,$value);
+ }
+ }
+
+ $this->y += 5;
+ $this->SetY($this->y);
+ $this->i++;
+ }
+
+ /**
+ * Draws the Item Detail for Iteration 1.
+ */
+ private function drawLineItems_1($db,$line,$invnum) {
+ global $C_translate;
+
+ if ($this->show_itemized != 1) return;
+ if ($line['price_type'] != 0 || $line['item_type'] != 5)
+ return;
+
+ $x = 10; $y = 5;
+ if ($this->i == 0 || $this->i%51 == 0) {
+ $this->AddPage();
+
+ $this->SetFont('arial','B',12);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_itemized_calls','setup_invoice'));
+ $this->Cell(0,0,$C_translate->translate('pdf_page','setup_invoice').$this->PageNo(),0,0,'R');
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number_small','setup_invoice').$invnum,0,0,'C');
+
+ # Draw table headers
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x,$y);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_from','setup_invoice'));
+ $this->SetX(69);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_to','setup_invoice'));
+ $this->SetX(119);
+ $this->Cell(0,0,'Date & Time');
+ $this->SetX(160);
+ $this->Cell(10,0,'Seconds' /*$C_translate->translate('pdf_item_min','setup_invoice')*/,0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_amount','setup_invoice'),0,0,'R');
+ $this->Line($x,$y+4,200,$y+4);
+ $y += 5;
+ $this->SetY($y);
+ }
+
+ if ($line['price_type'] != 0) {
+ $this->SetFont('arial','I',6);
+ } else {
+ $this->SetFont('arial','',6);
+ }
+
+ $val = $line['name'];
+ if (strlen($line['attr'])) {
+ $val = "";
+ $atrs = preg_split("/\r\n/", str_replace('\r\n',"\r\n",$line['attr']));
+ foreach ($atrs as $a) {
+ $parts = preg_split("/==/", $a);
+ switch ($parts[0]) {
+ case "Destination":
+ $this->SetX(69);
+ $this->Cell(0,0,$parts[1]);
+ $cc = ""; $npa = ""; $nxx = ""; $e164 = "";
+ if ($this->v->e164($parts[1], $e164, $cc, $npa, $nxx)) {
+ $this->SetX(89);
+ $this->Cell(0,0,substr($this->v->where_is($db, $cc, $npa, $nxx), 0, 20));
+ }
+ break;
+ case "Source":
+ $this->SetX(9);
+ $this->Cell(0,0,$parts[1]);
+ $cc = ""; $npa = ""; $nxx = ""; $e164 = "";
+ if ($this->v->e164($parts[1], $e164, $cc, $npa, $nxx)) {
+ $this->SetX(29);
+ $this->Cell(0,0,substr($this->v->where_is($db, $cc, $npa, $nxx), 0, 20));
+ }
+ break;
+ case "parent_service_id":
+ $sql = sqlSelect($db,"service","prod_attr","id=::".$parts[1]."::");
+ $rstmp = $db->Execute($sql);
+ $atrs2 = split("\r\n", $rstmp->fields['prod_attr']);
+ foreach ($atrs2 as $a2) {
+ $parts2 = split("==", $a2);
+ switch ($parts2[0]) {
+ case "station":
+ case "ported":
+ $val = $line['name']." for ".$parts2[1];
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case "station":
+ case "ported":
+ $val = $line['name']." for ".$parts[1];
+ break;
+ case "date_orig":
+ $this->SetX(119);
+ $this->Cell(0,0,date(UNIX_DATE_FORMAT." H:i:s",$parts[1]));
+ break;
+ case "voip_cdr_id":
+ $sql = "SELECT billsec, amount FROM ".AGILE_DB_PREFIX."voip_cdr WHERE site_id=".DEFAULT_SITE." AND id=".$parts[1];
+ $row = $db->GetRow($sql);
+ $this->SetX(160);
+ $this->Cell(10,0,$row[0],0,0,'R');
+ $this->SetX(160);
+ $this->Cell(0,0,$this->_currency($row[1]),0,0,'R');
+ $val = "";
+ default:
+ break;
+ }
+ }
+ }
+
+ $this->SetX(9);
+ $this->Cell(0,0, $val);
+ if ($line['price_type'] == 0) {
+ $this->SetX(160);
+ //$this->Cell(10,0, $line['qty']." M",0,0,'R');
+ } else {
+ $q = $line['qty'];
+ if(empty($q)) $q = 1;
+ $this->SetX(160);
+ $this->Cell(10,0, $line['qty'],0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0, $this->_currency($line['amount']), 0,0,'R');
+ }
+ $this->y += 5;
+ $this->SetY($this->y);
+ $this->i++;
+ }
+
+ /**
+ * This will draw the Summary Box, with the summary of the items
+ * on the invoice.
+ */
+ public function drawSummaryLineItems($inv) {
+ global $C_translate;
+
+ if (! $this->show_itemized)
+ return;
+
+ $items = $inv->summarizeLineItems($inv->print['invoiceitems']);
+
+ # Calculate the box size
+ $box = count($items) < $this->itemsSummaryMax ? count($items) : $this->itemsSummaryMax;
+
+ $x = 10; $y = $this->sum_y ? $this->sum_y : 55;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,5*(1+1+1+5+$box)+1,'',1,0,'',1);
+
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_cur_charge_summary','setup_invoice')); $y += 5;
+
+ $this->SetY($y);
+ $this->SetFont('arial','',9);
+
+ $i=0;
+ if (is_array($items)) {
+ foreach($items as $line) {
+ $this->SetX($x);
+
+ $q = $line['quantity'];
+ if (empty($q))
+ $q = 1;
+
+ $this->Cell(0,0,$q);
+ $this->SetX($x+8);
+ $this->Cell(0,0,sprintf('%s (%s)',$line['summaryname'],$this->_currency($line['price_base'])));
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($line['price_base']*$line['quantity']),0,0,'R');
+ $y += 5;
+ $this->SetY($y);
+ $i++;
+ if ($i > $this->itemsSummaryMax) {
+ $this->SetFont('arial','B',11);
+ $this->SetX($x);
+ $this->Cell(0,0,$C_translate->translate('pdf_summary','setup_invoice'));
+ break;
+ }
+ }
+
+ # Calculate our rounding error
+ $subtotal = 0;
+ foreach($items as $line)
+ $subtotal += $line['price_base']*$line['quantity'];
+
+ $subtotal = round($subtotal,2);
+
+ if (round($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt'],2) != $subtotal) {
+ $this->SetFont('arial','',9);
+ $this->SetX($x);
+ $this->Cell(0,0,'Rounding');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt']-$subtotal),0,0,'R');
+ $y += 5;
+ $this->SetY($y);
+ }
+
+ # @todo Draw discounts
+ # Sub total and tax.
+ $y += 5;
+ $this->SetY($y);
+ $this->SetFont('arial','B',9);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Sub Total');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Taxes');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['tax_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Total Charges');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Payments Received');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['billed_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Balance Due');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+ }
+}
+?>
diff --git a/modules/invoice/PDF/pdf_invoice_itemised-fpdi.inc.php b/modules/invoice/PDF/pdf_invoice_itemised-fpdi.inc.php
new file mode 100644
index 00000000..dde3d8c8
--- /dev/null
+++ b/modules/invoice/PDF/pdf_invoice_itemised-fpdi.inc.php
@@ -0,0 +1,638 @@
+Image($logo,$x,$y,$size);
+ }
+
+ /**
+ * Draw the Company Address
+ */
+ public function drawCompanyAddress($inv) {
+ global $C_translate;
+
+ # Add the company address next to the logo
+ $x = 40; $y = 9;
+
+ $this->SetFont('arial','B',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['NAME']); $y += 4;
+
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['TAXID']); $y += 6;
+
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['ADDRESS']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['site']['CITY'],$inv->print['site']['STATE'],$inv->print['site']['ZIP'])); $y += 4;
+
+ $y += 2;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Phone:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['PHONE']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Fax:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['FAX']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Web:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['URL']); $y += 4;
+ }
+
+ public function drawRemittenceStub($inv) {
+ global $C_translate;
+
+ # Draw the remittance line
+ $this->Line(9,195,200,195);
+
+ $x = 18; $y = 200;
+
+ $this->SetFont('arial','B',13);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_payment_remit','setup_invoice')); $y +=5;
+
+ $this->SetFont('arial','',8);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_return1','setup_invoice')); $y +=3;
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_return2','setup_invoice').' '.$inv->print['site']['NAME']);
+
+ # Due Date
+ $x = 110; $y = 200;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_bill_date','setup_invoice'));
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['date_orig']),0,0,'R');
+
+ # Account ID
+ $y = 205;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_account_number','setup_invoice'));
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->print['account']['id']),0,0,'R');
+
+ # Invoice number
+ $y = 210;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number','setup_invoice'));
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->getInvoiceNum()),0,0,'R');
+
+ # Company Address
+ $y = 216;
+ $this->SetFont('arial','',10);
+ $this->SetXY(18,$y); $this->Cell(0,0,$inv->print['site']['NAME']); $y += 4;
+ $this->SetXY(18,$y); $this->Cell(0,0,$inv->print['site']['ADDRESS']); $y += 4;
+ $this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['site']['CITY'],$inv->print['site']['STATE'],$inv->print['site']['ZIP'])); $y += 4;
+
+ # Previous Due
+ $y = 215;
+ $this->SetFont('arial','',9);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Due');
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()),0,0,'R');
+
+ $y = 219;
+ $this->SetFont('arial','',9);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_amount_due_by','setup_invoice').' '.date(UNIX_DATE_FORMAT,$inv->print['invoice']['due_date']));
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+
+ # Total Due
+ $y = 224;
+ $this->SetFont('arial','B',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Total Due');
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()+$inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+
+ # Draw the Customers Address
+ $x = 25; $y = 248;
+
+ $this->SetFont('arial','B',12);
+
+ if ($this->billToCompany && ! empty($inv->print['account']['company']))
+ $name = $inv->print['account']['company'];
+ else
+ $name = sprintf('%s %s',$inv->print['account']['first_name'],$inv->print['account']['last_name']);
+
+ $this->SetXY($x,$y); $this->Cell(0,0,html_entity_decode($name,ENT_NOQUOTES)); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s %s ',$inv->print['account']['address1'],$inv->print['account']['address2'])); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['account']['city'],$inv->print['account']['state'],$inv->print['account']['zip'])); $y += 5;
+ }
+
+ public function drawInvoiceHeader($inv) {
+ global $C_translate;
+
+ $x = 125; $y = 10;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,35+($inv->print['invoice']['billed_amt'] ? 5 : 0),'',1,0,'',1);
+
+ # Draw a box around the invoice due date and amount due.
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,'TAX INVOICE');
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->getInvoiceNum()),0,0,'R');
+
+ # Invoice number at top of page.
+ $y += 7;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_bill_date','setup_invoice')); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_amount_due_by','setup_invoice'));
+ $this->SetFont('arial','B',11);
+
+ $y -= 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['date_orig']),0,0,'R'); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['due_date']),0,0,'R');
+
+ $y += 5;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Due');
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()),0,0,'R');
+
+ $y += 5;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_current_charges','setup_invoice'));
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']),0,0,'R');
+
+ if ($inv->print['invoice']['billed_amt']) {
+ $y += 5;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Payments Received');
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+
+ $y += 5;
+ $this->SetFont('arial','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Total Payable');
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()+$inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+
+ #@todo Limit the size of the news to 6 lines
+ public function drawNews($news) {
+ global $C_translate;
+
+ if (! $news)
+ return;
+
+ $x = 9; $y = 170;
+
+ # Draw a box.
+ $this->SetFillColor(243);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,20,'',1,0,'',1);
+
+ $this->SetFont('arial','',8);
+ $this->SetXY($x,$y); $this->MultiCell(0,3,str_replace('\n',"\n",$news),0,'L',0);
+ }
+
+ #@todo make this list dynamic
+ public function drawPaymentMethods($inv) {
+ $x = 110; $y = 242;
+
+ # Draw a box.
+ $this->SetFillColor(235);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,32,'',1,0,'',1);
+
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x,$y); $this->Cell(0,0,'This invoice can also be paid by:'); $y += 4;
+
+ # Direct Debit
+ $logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-dd.png');
+ $this->Image($logo,$x+1,$y,8);
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Credit to our Bank Account'); $y += 3;
+ $this->SetFont('arial','',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'BSB:'); $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'ACCOUNT:'); $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'REF:'); $y += 3;
+
+ $y -= 9;
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x+30,$y); $this->Cell(0,0,'633-000'); $y += 3;
+ $this->SetXY($x+30,$y); $this->Cell(0,0,'120 440 821'); $y += 3;
+ $this->SetXY($x+30,$y); $this->Cell(0,0,$inv->getInvoiceID()); $y += 3;
+
+ # Direct Debit
+ $y += 3;
+ $logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-dd.png');
+ $this->Image($logo,$x+1,$y,8);
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Debit'); $y += 3;
+ $this->SetFont('arial','',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Please visit '.$inv->print['site']['URL']); $y += 3;
+
+# $r1 = $this->w - 40;
+# $r2 = $r1 + 30;
+# $y1 = 8;
+# $y2 = $y1 ;
+# $mid = $y1 + ($y2 / 2);
+# $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 2.5, 'F');
+
+# $this->addWaterMark('hello');
+# # Pay Pal
+# $y += 3;
+# $logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-pp.png');
+# $this->Image($logo,$x+1,$y,8);
+# $this->SetFont('arial','B',8);
+# $this->SetXY($x+10,$y); $this->Cell(0,0,'Pay Pal'); $y += 3;
+# $this->SetFont('arial','',8);
+# $this->SetXY($x+10,$y); $this->Cell(0,0,'Please visit '.$inv->print['site']['URL']); $y += 3;
+ }
+
+ /**
+ * Draw previous invoices due
+ */
+ public function drawSummaryInvoicesDue($items) {
+ $x = 125; $y = $this->sum_y ? $this->sum_y : 50;
+
+ # Calculate the box size
+ $box = count($items) < $this->itemsPreviousMax ? count($items) : $this->itemsPreviousMax;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,5*(1+$box)+1,'',1,0,'',1);
+
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Invoices due'); $y += 5;
+
+ $this->SetFont('arial','',11);
+ $i = 0;
+ $sum_total = 0;
+ foreach ($items as $line) {
+ if (++$i < $this->itemsPreviousMax) {
+ $this->SetXY($x,$y);
+ $this->Cell(0,0,sprintf('%s #%06s',date(UNIX_DATE_FORMAT,$line['date_orig']),$line['id']));
+ $this->Cell(0,0,$this->_currency($line['total_amt']-$line['billed_amt']),0,0,'R'); $y += 5;
+
+ } else {
+ $sum_total += $line['total_amt']-$line['billed_amt'];
+ }
+ }
+
+ if ($sum_total) {
+ $this->SetXY($x,$y);
+ $this->SetFont('arial','I',11);
+ $this->Cell(0,0,'Other invoices');
+ $this->SetFont('arial','',11);
+ $this->Cell(0,0,$this->_currency($sum_total),0,0,'R'); $y += 5;
+ }
+
+ $this->sum_y = $y+5;
+ }
+
+ /**
+ * Called before begining to loop the invoice_item table. Used to set initial values.
+ */
+ public function drawLineItems_pre($iteration) {
+ $this->iteration = $iteration;
+ if ($iteration>1)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Called once per line item to add to the PDF invoice. This function serves to
+ * direct each iteration to a different function which handles a specific piece
+ * of the PDF building puzzle.
+ */
+ public function drawLineItems($db,$line,$invnum) {
+ switch($this->iteration) {
+ case 0:
+ $this->drawLineItems_0($db,$line,$invnum);
+ break;
+
+ case 1:
+ $this->drawLineItems_1($db,$line,$invnum);
+ break;
+
+ default:
+ echo 'Unknown PDF iteration encountered. Halting.';
+ exit;
+ }
+ }
+
+ /**
+ * Draws the non-VoIP related items for iteration 0.
+ */
+ private function drawLineItems_0($db,$line,$invnum) {
+ global $C_translate;
+
+ if ($line['price_type'] == 0 && $line['item_type']==5)
+ return;
+
+ $x = 10; $y = 5;
+ if ($this->i == 0 || $this->i%51 == 0) {
+ $this->AddPage();
+
+ $this->SetFont('arial','B',12);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_itemized_charges','setup_invoice'));
+ $this->Cell(0,0,$C_translate->translate('pdf_page','setup_invoice').$this->PageNo(),0,0,'R');
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number_small','setup_invoice').$invnum,0,0,'C');
+
+ # Draw table headers
+ $y += 10;
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x,$y);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_description','setup_invoice'));
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_quantity','setup_invoice'));
+ $this->SetX($x+160);
+ $this->Cell(10,0,$C_translate->translate('pdf_item_cost','setup_invoice'),0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_amount','setup_invoice'),0,0,'R');
+ $this->Line($x,$y+2,200,$y+2);
+ $y += 5;
+ $this->SetY($y);
+ }
+
+ $this->SetFont('arial','',8);
+ $this->SetX($x);
+ $this->Cell(0,0,$line['name']);
+
+ if (isset($line['price_base'])) {
+ $this->SetX($x+160);
+ $this->Cell(10,0,$this->_currency($line['price_base']),0,0,'R');
+ }
+
+ if (isset($line['qty'])) {
+ $this->SetX($x+130);
+ $this->Cell(10,0,$line['qty'],0,0,'R');
+ }
+
+ $this->SetX($x+130);
+ $this->Cell(0,0,$this->_currency($line['total_amt']),0,0,'R');
+
+ if ($this->show_service_range && $line['daterange']) {
+ $this->SetFont('arial','I',7);
+ $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Service Period');
+ $this->SetFont('arial','',7);
+ $this->SetXY($x+40,$y); $this->Cell(0,0,$line['daterange']);
+ }
+
+ if ($line['domain']) {
+ $this->SetFont('arial','I',7);
+ $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Domain');
+ $this->SetFont('arial','',7);
+ $this->SetXY($x+40,$y); $this->Cell(0,0,$line['domain']);
+ }
+
+ if ($line['attr']) {
+ $showchars = 20;
+ foreach (explode("\n",$line['attr']) as $attr) {
+ list($field,$value) = explode('==',$attr);
+
+ $this->SetFont('arial','I',7);
+ $this->y += 3;
+ $this->SetXY(20,$this->y); $this->Cell(0,0,strlen($field) > $showchars ? substr($field,0,$showchars-2).'...' : $field);
+ $this->SetFont('arial','',7);
+ $this->SetXY(50,$this->y); $this->Cell(0,0,$value);
+ }
+ }
+
+ $this->y += 5;
+ $this->SetY($this->y);
+ $this->i++;
+ }
+
+ /**
+ * Draws the Item Detail for Iteration 1.
+ */
+ private function drawLineItems_1($db,$line,$invnum) {
+ global $C_translate;
+
+ if ($this->show_itemized != 1) return;
+ if ($line['price_type'] != 0 || $line['item_type'] != 5)
+ return;
+
+ $x = 10; $y = 5;
+ if ($this->i == 0 || $this->i%51 == 0) {
+ $this->AddPage();
+
+ $this->SetFont('arial','B',12);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_itemized_calls','setup_invoice'));
+ $this->Cell(0,0,$C_translate->translate('pdf_page','setup_invoice').$this->PageNo(),0,0,'R');
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number_small','setup_invoice').$invnum,0,0,'C');
+
+ # Draw table headers
+ $this->SetFont('arial','B',8);
+ $this->SetXY($x,$y);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_from','setup_invoice'));
+ $this->SetX(69);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_to','setup_invoice'));
+ $this->SetX(119);
+ $this->Cell(0,0,'Date & Time');
+ $this->SetX(160);
+ $this->Cell(10,0,'Seconds' /*$C_translate->translate('pdf_item_min','setup_invoice')*/,0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_amount','setup_invoice'),0,0,'R');
+ $this->Line($x,$y+4,200,$y+4);
+ $y += 5;
+ $this->SetY($y);
+ }
+
+ if ($line['price_type'] != 0) {
+ $this->SetFont('arial','I',6);
+ } else {
+ $this->SetFont('arial','',6);
+ }
+
+ $val = $line['name'];
+ if (strlen($line['attr'])) {
+ $val = "";
+ $atrs = preg_split("/\r\n/", str_replace('\r\n',"\r\n",$line['attr']));
+ foreach ($atrs as $a) {
+ $parts = preg_split("/==/", $a);
+ switch ($parts[0]) {
+ case "Destination":
+ $this->SetX(69);
+ $this->Cell(0,0,$parts[1]);
+ $cc = ""; $npa = ""; $nxx = ""; $e164 = "";
+ if ($this->v->e164($parts[1], $e164, $cc, $npa, $nxx)) {
+ $this->SetX(89);
+ $this->Cell(0,0,substr($this->v->where_is($db, $cc, $npa, $nxx), 0, 20));
+ }
+ break;
+ case "Source":
+ $this->SetX(9);
+ $this->Cell(0,0,$parts[1]);
+ $cc = ""; $npa = ""; $nxx = ""; $e164 = "";
+ if ($this->v->e164($parts[1], $e164, $cc, $npa, $nxx)) {
+ $this->SetX(29);
+ $this->Cell(0,0,substr($this->v->where_is($db, $cc, $npa, $nxx), 0, 20));
+ }
+ break;
+ case "parent_service_id":
+ $sql = sqlSelect($db,"service","prod_attr","id=::".$parts[1]."::");
+ $rstmp = $db->Execute($sql);
+ $atrs2 = split("\r\n", $rstmp->fields['prod_attr']);
+ foreach ($atrs2 as $a2) {
+ $parts2 = split("==", $a2);
+ switch ($parts2[0]) {
+ case "station":
+ case "ported":
+ $val = $line['name']." for ".$parts2[1];
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case "station":
+ case "ported":
+ $val = $line['name']." for ".$parts[1];
+ break;
+ case "date_orig":
+ $this->SetX(119);
+ $this->Cell(0,0,date(UNIX_DATE_FORMAT." H:i:s",$parts[1]));
+ break;
+ case "voip_cdr_id":
+ $sql = "SELECT billsec, amount FROM ".AGILE_DB_PREFIX."voip_cdr WHERE site_id=".DEFAULT_SITE." AND id=".$parts[1];
+ $row = $db->GetRow($sql);
+ $this->SetX(160);
+ $this->Cell(10,0,$row[0],0,0,'R');
+ $this->SetX(160);
+ $this->Cell(0,0,$this->_currency($row[1]),0,0,'R');
+ $val = "";
+ default:
+ break;
+ }
+ }
+ }
+
+ $this->SetX(9);
+ $this->Cell(0,0, $val);
+ if ($line['price_type'] == 0) {
+ $this->SetX(160);
+ //$this->Cell(10,0, $line['qty']." M",0,0,'R');
+ } else {
+ $q = $line['qty'];
+ if(empty($q)) $q = 1;
+ $this->SetX(160);
+ $this->Cell(10,0, $line['qty'],0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0, $this->_currency($line['amount']), 0,0,'R');
+ }
+ $this->y += 5;
+ $this->SetY($this->y);
+ $this->i++;
+ }
+
+ /**
+ * This will draw the Summary Box, with the summary of the items
+ * on the invoice.
+ */
+ public function drawSummaryLineItems($inv) {
+ global $C_translate;
+
+ if (! $this->show_itemized)
+ return;
+
+ $items = $inv->summarizeLineItems($inv->print['invoiceitems']);
+
+ # Calculate the box size
+ $box = count($items) < $this->itemsSummaryMax ? count($items) : $this->itemsSummaryMax;
+
+ $x = 10; $y = $this->sum_y ? $this->sum_y : 55;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-3); $this->Cell(0,5*(1+1+1+5+$box)+1,'',1,0,'',1);
+
+ $this->SetFont('arial','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_cur_charge_summary','setup_invoice')); $y += 5;
+
+ $this->SetY($y);
+ $this->SetFont('arial','',9);
+
+ $i=0;
+ if (is_array($items)) {
+ foreach($items as $line) {
+ $this->SetX($x);
+
+ $q = $line['quantity'];
+ if (empty($q))
+ $q = 1;
+
+ $this->Cell(0,0,$q);
+ $this->SetX($x+8);
+ $this->Cell(0,0,sprintf('%s (%s)',$line['summaryname'],$this->_currency($line['price_base'])));
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($line['price_base']*$line['quantity']),0,0,'R');
+ $y += 5;
+ $this->SetY($y);
+ $i++;
+ if ($i > $this->itemsSummaryMax) {
+ $this->SetFont('arial','B',11);
+ $this->SetX($x);
+ $this->Cell(0,0,$C_translate->translate('pdf_summary','setup_invoice'));
+ break;
+ }
+ }
+
+ # Calculate our rounding error
+ $subtotal = 0;
+ foreach($items as $line)
+ $subtotal += $line['price_base']*$line['quantity'];
+
+ $subtotal = round($subtotal,2);
+
+ if (round($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt'],2) != $subtotal) {
+ $this->SetFont('arial','',9);
+ $this->SetX($x);
+ $this->Cell(0,0,'Rounding');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt']-$subtotal),0,0,'R');
+ $y += 5;
+ $this->SetY($y);
+ }
+
+ # @todo Draw discounts
+ # Sub total and tax.
+ $y += 5;
+ $this->SetY($y);
+ $this->SetFont('arial','B',9);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Sub Total');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Taxes');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['tax_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Total Charges');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Payments Received');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['billed_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Balance Due');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+ }
+}
+?>
diff --git a/modules/invoice/PDF/pdf_invoice_itemised-tcpdf.inc.php b/modules/invoice/PDF/pdf_invoice_itemised-tcpdf.inc.php
new file mode 100644
index 00000000..3dd90684
--- /dev/null
+++ b/modules/invoice/PDF/pdf_invoice_itemised-tcpdf.inc.php
@@ -0,0 +1,624 @@
+Image($logo,$x,$y,$size);
+ }
+
+ /**
+ * Draw the Company Address
+ */
+ public function drawCompanyAddress($inv) {
+ global $C_translate;
+
+ # Add the company address next to the logo
+ $x = 40; $y = 7;
+
+ $this->SetFont('helvetica','B',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['NAME']); $y += 4;
+
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['TAXID']); $y += 6;
+
+ $this->SetXY($x,$y); $this->Cell(0,0,$inv->print['site']['ADDRESS']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['site']['CITY'],$inv->print['site']['STATE'],$inv->print['site']['ZIP'])); $y += 4;
+
+ $y += 2;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Phone:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['PHONE']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Fax:'); $this->SetXY($x+16,$y); $this->Cell(0,0,$inv->print['site']['FAX']); $y += 4;
+ $this->SetXY($x,$y); $this->Cell(0,0,'Web:'); $this->SetXY($x+16,$y); $this->addHtmlLink($inv->print['site']['URL'],$inv->print['site']['URL']); $y += 4;
+ }
+
+ public function drawRemittenceStub($inv) {
+ global $C_translate;
+
+ # Draw the remittance line
+ $this->Line(9,195,200,195);
+
+ $x = 18; $y = 200;
+
+ $this->SetFont('helvetica','B',13);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_payment_remit','setup_invoice')); $y +=5;
+
+ $this->SetFont('helvetica','',8);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_return1','setup_invoice')); $y +=3;
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_return2','setup_invoice').' '.$inv->print['site']['NAME']);
+
+ # Due Date
+ $x = 110; $y = 200;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_bill_date','setup_invoice'));
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['date_orig']),0,0,'R');
+
+ # Account ID
+ $y = 205;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_account_number','setup_invoice'));
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->print['account']['id']),0,0,'R');
+
+ # Invoice number
+ $y = 210;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number','setup_invoice'));
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->getInvoiceNum()),0,0,'R');
+
+ # Company Address
+ $y = 216;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY(18,$y); $this->Cell(0,0,$inv->print['site']['NAME']); $y += 4;
+ $this->SetXY(18,$y); $this->Cell(0,0,$inv->print['site']['ADDRESS']); $y += 4;
+ $this->SetXY(18,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['site']['CITY'],$inv->print['site']['STATE'],$inv->print['site']['ZIP'])); $y += 4;
+
+ # Previous Due
+ $y = 215;
+ $this->SetFont('helvetica','',9);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Due');
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()),0,0,'R');
+
+ $y = 219;
+ $this->SetFont('helvetica','',9);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_amount_due_by','setup_invoice').' '.date(UNIX_DATE_FORMAT,$inv->print['invoice']['due_date']));
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+
+ # Total Due
+ $y = 224;
+ $this->SetFont('helvetica','B',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Total Due');
+ $this->SetXY($x,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()+$inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+
+ # Draw the Customers Address
+ $x = 25; $y = 248;
+
+ $this->SetFont('helvetica','B',12);
+
+ if ($this->billToCompany && ! empty($inv->print['account']['company']))
+ $name = $inv->print['account']['company'];
+ else
+ $name = sprintf('%s %s',$inv->print['account']['first_name'],$inv->print['account']['last_name']);
+
+ $this->SetXY($x,$y); $this->Cell(0,0,html_entity_decode($name,ENT_NOQUOTES)); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s %s ',$inv->print['account']['address1'],$inv->print['account']['address2'])); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%s, %s %s',$inv->print['account']['city'],$inv->print['account']['state'],$inv->print['account']['zip'])); $y += 5;
+ }
+
+ public function drawInvoiceHeader($inv) {
+ global $C_translate;
+
+ $x = 125; $y = 10;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-1); $this->Cell(0,35+($inv->print['invoice']['billed_amt'] ? 5 : 0),'',1,0,'',1);
+
+ # Draw a box around the invoice due date and amount due.
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,'TAX INVOICE');
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,sprintf('%06s',$inv->getInvoiceNum()),0,0,'R');
+
+ # Invoice number at top of page.
+ $y += 7;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_bill_date','setup_invoice')); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_amount_due_by','setup_invoice'));
+
+ $y -= 5;
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['date_orig']),0,0,'R'); $y += 5;
+ $this->SetXY($x,$y); $this->Cell(0,0,date(UNIX_DATE_FORMAT,$inv->print['invoice']['due_date']),0,0,'R');
+
+ $y += 5;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Due');
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()),0,0,'R');
+
+ $y += 5;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_current_charges','setup_invoice'));
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']),0,0,'R');
+
+ if ($inv->print['invoice']['billed_amt']) {
+ $y += 5;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Payments Received');
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+
+ $y += 5;
+ $this->SetFont('helvetica','',10);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Total Payable');
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x+55,$y); $this->Cell(0,0,$this->_currency($inv->getPreviousBalance()+$inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+
+ #@todo Limit the size of the news to 6 lines
+ public function drawNews($news) {
+ global $C_translate;
+
+ if (! $news)
+ return;
+
+ $x = 9; $y = 170;
+
+ # Draw a box.
+ $this->SetFillColor(243);
+ $this->SetXY($x-1,$y-1); $this->Cell(0,20,'',1,0,'',1);
+
+ $this->SetFont('helvetica','',8);
+ $this->SetXY($x,$y); $this->MultiCell(0,3,str_replace('\n',"\n",$news),0,'L',0);
+ }
+
+ #@todo make this list dynamic
+ public function drawPaymentMethods($inv) {
+ $x = 110; $y = 242;
+
+ # Draw a box.
+ $this->SetFillColor(235);
+ $this->SetXY($x-1,$y-2); $this->Cell(0,32,'',1,0,'',1);
+
+ $this->SetFont('helvetica','B',8);
+ $this->SetXY($x,$y); $this->Cell(0,0,'This invoice can also be paid by:'); $y += 4;
+
+ # Direct Debit
+ $logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-dd.png');
+ $this->Image($logo,$x+1,$y,8);
+ $this->SetFont('helvetica','B',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Credit to our Bank Account'); $y += 3;
+ $this->SetFont('helvetica','',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'BSB:'); $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'ACCOUNT:'); $y += 3;
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'REF:'); $y += 3;
+
+ $y -= 9;
+ $this->SetFont('helvetica','B',8);
+ $this->SetXY($x+30,$y); $this->Cell(0,0,'633-000'); $y += 3;
+ $this->SetXY($x+30,$y); $this->Cell(0,0,'120 440 821'); $y += 3;
+ $this->SetXY($x+30,$y); $this->Cell(0,0,$inv->getInvoiceID()); $y += 3;
+
+ # Direct Debit
+ $y += 3;
+ $logo = sprintf('%s/%s',PATH_THEMES.DEFAULT_THEME,'invoice/invoice-payment-dd.png');
+ $this->Image($logo,$x+1,$y,8);
+ $this->SetFont('helvetica','B',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Direct Debit'); $y += 3;
+ $this->SetFont('helvetica','',8);
+ $this->SetXY($x+10,$y); $this->Cell(0,0,'Please visit '); $this->SetXY($x+30,$y); $this->addHtmlLink($inv->print['site']['URL'].'?_page=invoice:user_view&id='.$inv->getInvoiceNum(),$inv->print['site']['URL']); $y += 3;
+ }
+
+ /**
+ * Draw previous invoices due
+ */
+ public function drawSummaryInvoicesDue($items) {
+ $x = 125; $y = $this->sum_y ? $this->sum_y : 50;
+
+ # Calculate the box size
+ $box = count($items) < $this->itemsPreviousMax ? count($items) : $this->itemsPreviousMax;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-1); $this->Cell(0,5*(1+$box)+1,'',1,0,'',1);
+
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,'Previous Invoices due'); $y += 5;
+
+ $this->SetFont('helvetica','',11);
+ $i = 0;
+ $sum_total = 0;
+ foreach ($items as $line) {
+ if (++$i < $this->itemsPreviousMax) {
+ $this->SetXY($x,$y);
+ $this->Cell(0,0,sprintf('%s #%06s',date(UNIX_DATE_FORMAT,$line['date_orig']),$line['id']));
+ $this->Cell(0,0,$this->_currency($line['total_amt']-$line['billed_amt']),0,0,'R'); $y += 5;
+
+ } else {
+ $sum_total += $line['total_amt']-$line['billed_amt'];
+ }
+ }
+
+ if ($sum_total) {
+ $this->SetXY($x,$y);
+ $this->SetFont('helvetica','I',11);
+ $this->Cell(0,0,'Other invoices');
+ $this->SetFont('helvetica','',11);
+ $this->Cell(0,0,$this->_currency($sum_total),0,0,'R'); $y += 5;
+ }
+
+ $this->sum_y = $y+5;
+ }
+
+ /**
+ * Called before begining to loop the invoice_item table. Used to set initial values.
+ */
+ public function drawLineItems_pre($iteration) {
+ $this->iteration = $iteration;
+ if ($iteration>1)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Called once per line item to add to the PDF invoice. This function serves to
+ * direct each iteration to a different function which handles a specific piece
+ * of the PDF building puzzle.
+ */
+ public function drawLineItems($db,$line,$invnum) {
+ switch($this->iteration) {
+ case 0:
+ $this->drawLineItems_0($db,$line,$invnum);
+ break;
+
+ case 1:
+ $this->drawLineItems_1($db,$line,$invnum);
+ break;
+
+ default:
+ echo 'Unknown PDF iteration encountered. Halting.';
+ exit;
+ }
+ }
+
+ /**
+ * Draws the non-VoIP related items for iteration 0.
+ * @todo need to make sure that this pages well, when there are many items (with many sub details).
+ * @tood Need to replicate this to the other fpdf files
+ */
+ private function drawLineItems_0($db,$line,$invnum) {
+ global $C_translate;
+
+ if ($line['price_type'] == 0 && $line['item_type']==5)
+ return;
+
+ $x = 10;
+ if ($this->i == 0 || $this->i%51 == 0) {
+ $this->y = 5;
+ $this->AddPage();
+
+ $this->SetFont('helvetica','B',12);
+ $this->SetXY($x,$this->y); $this->Cell(0,0,$C_translate->translate('pdf_itemized_charges','setup_invoice'));
+ $this->Cell(0,0,$C_translate->translate('pdf_page','setup_invoice').$this->PageNo(),0,0,'R');
+ $this->SetXY($x,$this->y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number_small','setup_invoice').$invnum,0,0,'C');
+
+ # Draw table headers
+ $this->y += 10;
+ $this->SetFont('helvetica','B',8);
+ $this->SetXY($x,$this->y);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_description','setup_invoice'));
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_quantity','setup_invoice'));
+ $this->SetX($x+160);
+ $this->Cell(10,0,$C_translate->translate('pdf_item_cost','setup_invoice'),0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_amount','setup_invoice'),0,0,'R');
+ $this->Line($x,$this->y+4,200,$this->y+4);
+ $this->y += 5;
+ $this->SetY($this->y);
+ }
+
+ $this->SetFont('helvetica','',8);
+ $this->SetX($x);
+ $this->Cell(0,0,$line['name']);
+
+ if (isset($line['price_base'])) {
+ $this->SetX($x+160);
+ $this->Cell(10,0,$this->_currency($line['price_base']),0,0,'R');
+ }
+
+ if (isset($line['qty'])) {
+ $this->SetX($x+130);
+ $this->Cell(10,0,$line['qty'],0,0,'R');
+ }
+
+ $this->SetX($x+130);
+ $this->Cell(0,0,$this->_currency($line['total_amt']),0,0,'R');
+
+ if ($this->show_service_range && $line['daterange']) {
+ $this->SetFont('helvetica','I',7);
+ $this->y += 3;
+ $this->SetXY($x+10,$this->y); $this->Cell(0,0,'Service Period');
+ $this->SetFont('helvetica','',7);
+ $this->SetXY($x+40,$this->y); $this->Cell(0,0,$line['daterange']);
+ }
+
+ if ($line['domain']) {
+ $this->SetFont('helvetica','I',7);
+ $this->y += 3;
+ $this->SetXY($x+10,$this->y); $this->Cell(0,0,'Domain');
+ $this->SetFont('helvetica','',7);
+ $this->SetXY($x+40,$this->y); $this->Cell(0,0,$line['domain']);
+ }
+
+ if ($line['attr']) {
+ $showchars = 20;
+ foreach (explode("\n",$line['attr']) as $attr) {
+ list($field,$value) = explode('==',$attr);
+
+ $this->SetFont('helvetica','I',7);
+ $this->y += 3;
+ $this->SetXY(20,$this->y); $this->Cell(0,0,strlen($field) > $showchars ? substr($field,0,$showchars-2).'...' : $field);
+ $this->SetFont('helvetica','',7);
+ $this->SetXY(50,$this->y); $this->Cell(0,0,$value);
+ }
+ }
+
+ $this->y += 5;
+ $this->SetY($this->y);
+ $this->i++;
+ }
+
+ /**
+ * Draws the Item Detail for Iteration 1.
+ */
+ private function drawLineItems_1($db,$line,$invnum) {
+ global $C_translate;
+
+ if ($this->show_itemized != 1) return;
+ if ($line['price_type'] != 0 || $line['item_type'] != 5)
+ return;
+
+ $x = 10; $this->y = 5;
+ if ($this->i == 0 || $this->i%51 == 0) {
+ $this->AddPage();
+
+ $this->SetFont('helvetica','B',12);
+ $this->SetXY($x,$this->y); $this->Cell(0,0,$C_translate->translate('pdf_itemized_calls','setup_invoice'));
+ $this->Cell(0,0,$C_translate->translate('pdf_page','setup_invoice').$this->PageNo(),0,0,'R');
+ $this->SetXY($x,$this->y); $this->Cell(0,0,$C_translate->translate('pdf_invoice_number_small','setup_invoice').$invnum,0,0,'C');
+
+ # Draw table headers
+ $this->SetFont('helvetica','B',8);
+ $this->SetXY($x,$this->y);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_from','setup_invoice'));
+ $this->SetX(69);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_to','setup_invoice'));
+ $this->SetX(119);
+ $this->Cell(0,0,'Date & Time');
+ $this->SetX(160);
+ $this->Cell(10,0,'Seconds' /*$C_translate->translate('pdf_item_min','setup_invoice')*/,0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$C_translate->translate('pdf_item_amount','setup_invoice'),0,0,'R');
+ $this->Line($x,$this->y+4,200,$this->y+4);
+ $this->y += 5;
+ $this->SetY($this->y);
+ }
+
+ if ($line['price_type'] != 0) {
+ $this->SetFont('helvetica','I',6);
+ } else {
+ $this->SetFont('helvetica','',6);
+ }
+
+ $val = $line['name'];
+ if (strlen($line['attr'])) {
+ $val = "";
+ $atrs = preg_split("/\r\n/", str_replace('\r\n',"\r\n",$line['attr']));
+ foreach ($atrs as $a) {
+ $parts = preg_split("/==/", $a);
+ switch ($parts[0]) {
+ case "Destination":
+ $this->SetX(69);
+ $this->Cell(0,0,$parts[1]);
+ $cc = ""; $npa = ""; $nxx = ""; $e164 = "";
+ if ($this->v->e164($parts[1], $e164, $cc, $npa, $nxx)) {
+ $this->SetX(89);
+ $this->Cell(0,0,substr($this->v->where_is($db, $cc, $npa, $nxx), 0, 20));
+ }
+ break;
+ case "Source":
+ $this->SetX(9);
+ $this->Cell(0,0,$parts[1]);
+ $cc = ""; $npa = ""; $nxx = ""; $e164 = "";
+ if ($this->v->e164($parts[1], $e164, $cc, $npa, $nxx)) {
+ $this->SetX(29);
+ $this->Cell(0,0,substr($this->v->where_is($db, $cc, $npa, $nxx), 0, 20));
+ }
+ break;
+ case "parent_service_id":
+ $sql = sqlSelect($db,"service","prod_attr","id=::".$parts[1]."::");
+ $rstmp = $db->Execute($sql);
+ $atrs2 = split("\r\n", $rstmp->fields['prod_attr']);
+ foreach ($atrs2 as $a2) {
+ $parts2 = split("==", $a2);
+ switch ($parts2[0]) {
+ case "station":
+ case "ported":
+ $val = $line['name']." for ".$parts2[1];
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case "station":
+ case "ported":
+ $val = $line['name']." for ".$parts[1];
+ break;
+ case "date_orig":
+ $this->SetX(119);
+ $this->Cell(0,0,date(UNIX_DATE_FORMAT." H:i:s",$parts[1]));
+ break;
+ case "voip_cdr_id":
+ $sql = "SELECT billsec, amount FROM ".AGILE_DB_PREFIX."voip_cdr WHERE site_id=".DEFAULT_SITE." AND id=".$parts[1];
+ $row = $db->GetRow($sql);
+ $this->SetX(160);
+ $this->Cell(10,0,$row[0],0,0,'R');
+ $this->SetX(160);
+ $this->Cell(0,0,$this->_currency($row[1]),0,0,'R');
+ $val = "";
+ default:
+ break;
+ }
+ }
+ }
+
+ $this->SetX(9);
+ $this->Cell(0,0, $val);
+ if ($line['price_type'] == 0) {
+ $this->SetX(160);
+ //$this->Cell(10,0, $line['qty']." M",0,0,'R');
+ } else {
+ $q = $line['qty'];
+ if(empty($q)) $q = 1;
+ $this->SetX(160);
+ $this->Cell(10,0, $line['qty'],0,0,'R');
+ $this->SetX($x+135);
+ $this->Cell(0,0, $this->_currency($line['amount']), 0,0,'R');
+ }
+ $this->y += 5;
+ $this->SetY($this->y);
+ $this->i++;
+ }
+
+ /**
+ * This will draw the Summary Box, with the summary of the items
+ * on the invoice.
+ */
+ public function drawSummaryLineItems($inv) {
+ global $C_translate;
+
+ if (! $this->show_itemized)
+ return;
+
+ $items = $inv->summarizeLineItems($inv->print['invoiceitems']);
+
+ # Calculate the box size
+ $box = count($items) < $this->itemsSummaryMax ? count($items) : $this->itemsSummaryMax;
+
+ $x = 10; $y = $this->sum_y ? $this->sum_y : 55;
+
+ # Draw a box.
+ $this->SetFillColor(245);
+ $this->SetXY($x-1,$y-1); $this->Cell(0,5*(1+1+1+5+$box)+1,'',1,0,'',1);
+
+ $this->SetFont('helvetica','B',11);
+ $this->SetXY($x,$y); $this->Cell(0,0,$C_translate->translate('pdf_cur_charge_summary','setup_invoice')); $y += 5;
+
+ $this->SetY($y);
+ $this->SetFont('helvetica','',9);
+
+ $i=0;
+ if (is_array($items)) {
+ foreach($items as $line) {
+ $this->SetX($x);
+
+ $q = $line['quantity'];
+ if (empty($q))
+ $q = 1;
+
+ $this->Cell(0,0,$q);
+ $this->SetX($x+8);
+ $this->Cell(0,0,sprintf('%s (%s)',$line['summaryname'],$this->_currency($line['price_base'])));
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($line['price_base']*$line['quantity']),0,0,'R');
+ $y += 5;
+ $this->SetY($y);
+ $i++;
+ if ($i > $this->itemsSummaryMax) {
+ $this->SetFont('helvetica','B',11);
+ $this->SetX($x);
+ $this->Cell(0,0,$C_translate->translate('pdf_summary','setup_invoice'));
+ break;
+ }
+ }
+
+ # Calculate our rounding error
+ $subtotal = 0;
+ foreach($items as $line)
+ $subtotal += $line['price_base']*$line['quantity'];
+
+ $subtotal = round($subtotal,2);
+
+ if (round($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt'],2) != $subtotal) {
+ $this->SetFont('helvetica','',9);
+ $this->SetX($x);
+ $this->Cell(0,0,'Rounding');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt']-$subtotal),0,0,'R');
+ $y += 5;
+ $this->SetY($y);
+ }
+
+ # @todo Draw discounts
+ # Sub total and tax.
+ $y += 5;
+ $this->SetY($y);
+ $this->SetFont('helvetica','B',9);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Sub Total');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['tax_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Taxes');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['tax_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Total Charges');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Payments Received');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['billed_amt']),0,0,'R');
+
+ $y += 5;
+ $this->SetY($y);
+ $this->SetX($x+8);
+ $this->Cell(0,0,'Balance Due');
+ $this->SetX($x+135);
+ $this->Cell(0,0,$this->_currency($inv->print['invoice']['total_amt']-$inv->print['invoice']['billed_amt']),0,0,'R');
+ }
+ }
+}
+?>
diff --git a/modules/invoice/auth.inc.php b/modules/invoice/auth.inc.php
index 59fea1f5..8588bf9b 100644
--- a/modules/invoice/auth.inc.php
+++ b/modules/invoice/auth.inc.php
@@ -1,13 +1,41 @@
- 'invoice', 'method' => 'user_search'),
-Array ('module' => 'invoice', 'method' => 'user_search_show'),
-Array ('module' => 'invoice', 'method' => 'user_view'),
-Array ('module' => 'invoice', 'method' => 'pdf'),
-Array ('module' => 'invoice', 'method' => 'checkoutnow'),
-Array ('module' => 'invoice', 'method' => 'checkout_multiple_preview'),
-Array ('module' => 'invoice', 'method' => 'custom_tracking'),
-Array ('module' => 'invoice', 'method' => 'has_unpaid'),
+
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
+ *
+ * @link http://www.agileco.com/
+ * @copyright 2004-2008 Agileco, LLC.
+ * @license http://www.agileco.com/agilebill/license1-4.txt
+ * @author Tony Landis
+ * @package AgileBill
+ * @subpackage Modules:Invoice
+ */
+
+/**
+ * The main AgileBill Invoice Class
+ *
+ * @package AgileBill
+ */
+
+$auth_methods = array (
+ array('module'=>'invoice','method'=>'user_search'),
+ array('module'=>'invoice','method'=>'user_search_show'),
+ array('module'=>'invoice','method'=>'user_view'),
+ array('module'=>'invoice','method'=>'pdf'),
+ array('module'=>'invoice','method'=>'checkoutnow'),
+ array('module'=>'invoice','method'=>'tpl_checkout_multiple_preview'),
+ array('module'=>'invoice','method'=>'custom_tracking'),
+ array('module'=>'invoice','method'=>'has_unpaid'),
);
-?>
\ No newline at end of file
+?>
diff --git a/modules/invoice/invoice.inc.php b/modules/invoice/invoice.inc.php
index 9bd17e72..57841819 100644
--- a/modules/invoice/invoice.inc.php
+++ b/modules/invoice/invoice.inc.php
@@ -1,346 +1,612 @@
+ * @copyright 2009 Deon George
+ * @link http://osb.leenooks.net
*
* @link http://www.agileco.com/
* @copyright 2004-2008 Agileco, LLC.
* @license http://www.agileco.com/agilebill/license1-4.txt
- * @author Tony Landis
+ * @author Tony Landis
* @package AgileBill
- * @version 1.4.93
+ * @subpackage Modules:Invoice
*/
-
-
+
/**
- * The main AgileBill Invoice Class
+ * The main AgileBill Invoice Class
+ *
+ * @package AgileBill
+ * @subpackage Modules:Invoice
*/
-class invoice
-{
- /** Enable summary invoice view that rolls multiple instances of the same sku w/identical base&setup price & attributes into one line item */
- var $summarizeInvoice=true;
-
- /**
- * Holds sku's of line items to exclude from invoice summarys (pdf view only)
- *
- * @var array
- */
- var $summarizeInvoiceExclude;
-
+class invoice extends OSB_module {
+ # Array holding all our print information
+ public $print = array();
+ # Enable summary invoice view that rolls multiple instances of the same sku w/identical base&setup price & attributes into one line item
+ private $summarizeInvoice = true;
+ # Holds sku's of line items to exclude from invoice summarys (pdf view only)
+ # @todo not implemented
+ private $summarizeInvoiceExclude = array();
+
/** Invoice type, 0=new, 1=recurr */
var $type=0;
-
- /** Invoice Creation Timestamp */
- var $date_orig;
-
- /** Last modification Timestamp */
- var $date_last;
-
- /** Invoice Id */
- var $record_id;
-
- /** Invoice Item Id */
- var $item_id=1;
-
- /** Parent Invoice Id for recurring */
- var $parent_id;
-
- /** Account Id for invoice */
- var $account_id;
-
- /** Affiliate Id of Invoice */
- var $affiliate_id;
-
- /** Account Billing Id */
- var $account_billing_id;
-
- /** Campaign Id */
- var $campaign_id;
-
- /** Reseller Id */
- var $reseller_id;
- /** Billed Currency Id */
- var $billed_currency_id;
-
- /** Actual Billed Currency selected by Client */
- var $actual_billed_currency_id;
-
- /** Checkout Plugin Id */
- var $checkout_plugin_id;
-
- /** Array of checkout plugin data returned by checkout plugin */
- var $checkout_plugin_data;
-
+ # Invoice Creation Timestamp
+ private $date_orig;
+ # Last modification Timestamp
+ private $date_last;
+ # Invoice Id
+ # @todo change to invoice_id?
+ public $record_id;
+
+ /** Invoice Item Id */
+ private $item_id=0;
+
+ # Parent Invoice Id for recurring
+ public $parent_id;
+ # Account Id for invoice
+ public $account_id;
+ # Affiliate Id of Invoice
+ public $affiliate_id;
+ # Account Billing Id
+ public $account_billing_id;
+ # Campaign Id
+ public $campaign_id;
+ # Reseller Id
+ public $reseller_id;
+ # Billed Currency Id
+ public $billed_currency_id;
+ # Actual Billed Currency selected by Client
+ public $actual_billed_currency_id;
+ # Checkout Plugin Id
+ public $checkout_plugin_id;
+ # array of checkout plugin data returned by checkout plugin
+ public $checkout_plugin_data;
+
/** Current Notice Count */
var $notice_count=0;
-
+
/** Last Notice Timestamp */
- var $notice_date;
-
- /** Due Date Timestamp */
- var $due_date;
-
+ var $notice_date;
+
+ # Due Date Timestamp
+ private $due_date;
+
/** Net Term Id */
var $net_term_id=false;
-
+
/** Net Term Last Notice/Late fee Timestamp */
var $net_term_date_last;
-
+
/** Net Term Interval Count */
var $net_term_intervals=0;
-
- /** Process Status */
- var $process_status=0;
-
- /** Billing Status */
- var $billing_status=0;
-
+
+ # Process Status
+ private $process_status = 0;
+ # Billing Status
+ private $billing_status = 0;
+
/** Suspend Billing Status */
var $suspend_billing=0;
-
- /** Printed Invoice Status */
- var $print_status=0;
-
+
+ # Printed Invoice Status
+ private $print_status = 0;
+
/** Refunded Invoice Status */
var $refund_status=0;
-
+
/** Calcuate Taxes */
- var $tax=true;
+ var $tax=true;
/** Calculate Discounts */
- var $discount=true;
-
- /** Total Invoice Amount */
- var $total_amt=0;
-
- /** Total Amount Billed */
- var $billed_amt=0;
-
+ var $discount=true;
+
+ # Total Invoice Amount
+ public $total_amt = 0;
+ # Total Amount Billed
+ private $billed_amt = 0;
+
/** Actual total amount billed (converted to local) */
var $actual_billed_amt=0;
-
- /** Total Tax Amount */
- var $tax_amt=0;
-
- /** Total Discount Amount */
- var $discount_amt=0;
-
+
+ # Total Tax Amount
+ public $tax_amt = 0;
+ # Total Discount Amount
+ public $discount_amt = 0;
+
/** Recurring Amount */
- var $recur_amt;
-
- /** Recurring Array for Later Processing */
+ public $recur_amt = 0;
+
+ /** Recurring array for Later Processing */
var $recur_arr;
-
- /** IP Address of User */
- var $ip=USER_IP;
-
- /** Array of the Invoice items */
+
+ # IP Address of User
+ private $ip = USER_IP;
+
+ /** array of the Invoice items */
var $invoice_item;
-
- /** Array of the discounts for the Invoice items */
+
+ /** array of the discounts for the Invoice items */
var $item_discount;
-
- /** Array of the taxes for the Invoice Items */
+
+ /** array of the taxes for the Invoice Items */
var $item_tax;
-
+
/** Tracking to determine payment options */
var $any_new=false;
var $any_trial=false;
var $any_recurring=false;
-
+
/** Invoice Config Global Options */
var $invoice_delivery=1;
- var $invoice_format=0;
- var $notice_max=MAX_BILLING_NOTICE;
- var $grace_period=GRACE_PERIOD;
-
-
-
+ var $invoice_format=0;
+ var $notice_max=MAX_BILLING_NOTICE;
+ var $grace_period=GRACE_PERIOD;
+
/**
- * Get the global level invoice settings
+ * Determine the number of days in advance an invoice should be generated.
+ * Invoices are generated when the greater of:
+ * + system default (setup:max_inv_gen_period), (to be deprecated)
+ * + system default (setup_invoice:invoice_advance_gen),
*/
- function setupGlobal() {
- $db=&DB();
- $invopt=$db->Execute(sqlSelect($db,"setup_invoice","*",""));
- if($invopt && $invopt->RecordCount()) {
- $this->invoice_delivery=$invopt->fields['invoice_delivery'];
- $this->invoice_format=$invopt->fields['invoice_show_itemized'];
+ public function invoice_days() {
+ $db = &DB();
+
+ # Get the max invoice days from the setup_invoice table
+ $days = 0;
+
+ # First from the setup table.
+ $setup = $db->Execute(sqlSelect($db,'setup','max_inv_gen_period',''));
+ if (isset($setup->fields['max_inv_gen_period']))
+ $days = $setup->fields['max_inv_gen_period'];
+
+ # Then from the setup_invoice table.
+ $setup = $db->Execute(sqlSelect($db,'setup_invoice','invoice_advance_gen,advance_notice',''));
+ if (isset($setup->fields['invoice_advance_gen']) && $setup->fields['invoice_advance_gen'] > $days)
+ $days = $setup->fields['invoice_advance_gen'];
+
+ if (isset($setup->fields['advance_notice']) && $setup->fields['advance_notice'] > $days)
+ $days = $setup->fields['advance_notice'];
+
+ return $days;
+ }
+
+ /**
+ * Return the SQL that determines which invoices need to be generated
+ *
+ * Invoices are generated when the greater of:
+ * + system default (setup:max_inv_gen_period), (to be deprecated)
+ * + system default (setup_invoice:invoice_advance_gen),
+ * + the account setting (account:invoice_advance_gen)
+ * + the net_terms setting (net_term:invoice_advance_gen) (linked from the account:net_term_id))
+ *
+ * This function can be called to display the SQL that is need to generate upcoming invoices.
+ *
+ * @param string The SQL to use in the SELECT portion of the query, to return the fields
+ * @param int Days in advance of the normal invoice generation date to obtain
+ * @param int|array Limit the query to just a(n) (set of) Account ID(s)
+ * @param string The SQL to use in the ORDER BY portion of the query.
+ */
+ public function sql_invoice_soon($fields=null,$adddays=0,$account=null,$orderby=null) {
+ global $C_list;
+
+ $db = &DB();
+
+ # Get the max invoice days from the system configuration tables.
+ $days = $this->invoice_days();
+
+ # Pre-notification date for service
+ $max_date = date('Y-m-d',time()+(($adddays+$days)*86400));
+
+ if ($account) {
+ if (is_array($account))
+ $account_where = sprintf('AND account.id IN (%s)',implode(',',$account));
+ else
+ $account_where = sprintf('AND account.id=%s',$account);
+
+ } else
+ $account_where = '';
+
+ if (is_null($fields))
+ $fields = "DISTINCT service.id AS sid,account.id AS aid,invoice.id AS iid,FROM_UNIXTIME(service.date_next_invoice,'%Y-%m-%d') AS invoice_date,service.sku AS sku,service.price AS price,account.first_name AS first_name,account.last_name AS last_name,account.currency_id AS billed_currency_id";
+
+ if (is_null($orderby))
+ $orderby = 'ORDER BY aid,invoice_date,sid';
+
+ $p=AGILE_DB_PREFIX; $s=DEFAULT_SITE;
+
+ // @todo NET_TERM is not tested.
+ if ($C_list->is_installed('net_term')) {
+ $net_term = "LEFT JOIN {$p}net_term AS net_term ON (account.net_term_id=net_term.id AND net_term.site_id={$s})";
+ $net_term_where = "OR ((net_term.invoice_advance_gen!='' OR net_term.invoice_advance_gen IS NOT NULL) AND service.date_next_invoice<=((86400*(net_term.invoice_advance_gen+{$adddays}+{$days}))+(UNIX_TIMESTAMP(CURDATE()))))";
+ } else {
+ $net_term = '';
+ $net_term_where = '';
+ }
+
+ $sql = "
+SELECT {$fields}
+FROM {$p}service AS service
+JOIN {$p}account AS account ON (service.account_id=account.id AND account.site_id={$s})
+LEFT JOIN {$p}invoice AS invoice ON (service.invoice_id=invoice.id AND invoice.site_id={$s})
+{$net_term}
+WHERE service.site_id={$s}
+AND service.active=1
+AND price > 0
+AND (service.suspend_billing IS NULL OR service.suspend_billing=0)
+AND (service.date_next_invoice>0 AND service.date_next_invoice IS NOT NULL)
+AND (
+ ((account.invoice_advance_gen!='' OR account.invoice_advance_gen IS NOT NULL) AND service.date_next_invoice<=((86400*(account.invoice_advance_gen+{$adddays}+{$days}))+(UNIX_TIMESTAMP(CURDATE()))))
+{$net_term_where}
+ OR service.date_next_invoice<=UNIX_TIMESTAMP('{$max_date}')
+)
+{$account_where} {$orderby}";
+
+ return $sql;
+ }
+
+ /**
+ * List all invoices that will be generated soon
+ */
+ public function invoicesoon($VAR) {
+ global $smarty,$C_list;
+
+ $db = &DB();
+
+ # Then from the setup_invoice table.
+ $setup = $db->Execute(sqlSelect($db,'setup_invoice','advance_notice',''));
+
+ # Run the database query
+ $result = $db->Execute($this->sql_invoice_soon(null,$setup->fields['advance_notice']));
+
+ $invoice = array();
+ $i = 0;
+ $amount = 0;
+ while (! $result->EOF) {
+ $result->fields['_C'] = ++$i%2 ? 'row1' : 'row2';
+ array_push($invoice,$result->fields);
+ $amount += $result->fields['price'];
+ $result->MoveNext();
+ }
+
+ # Error reporting
+ if ($result === false) {
+ global $C_debug;
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+
+ return false;
+ }
+
+ $results = $result->RecordCount();
+
+ # Create the definition for fast-forwarding to a single record:
+ if ($results == 1 && ! isset($this->fast_forward))
+ $smarty->assign('record_id',$record_id);
+
+ # Create the search record:
+ if($results > 0) {
+ # create the search record
+ include_once(PATH_CORE.'search.inc.php');
+ $search = new CORE_search;
+
+ $arr['module'] = $this->module;
+ $arr['sql'] = $this->sql_invoice_soon();
+# $arr['limit'] = $limit;
+# $arr['order_by']= $order_by;
+ $arr['results'] = $results;
+ $search->add($arr);
+
+ # define the search id and other parameters for Smarty
+ $smarty->assign('search_id', $search->id);
+
+ # page:
+ $smarty->assign('page', '1');
+
+ # limit:
+# $smarty->assign('limit', $limit);
+
+ # order_by:
+# $smarty->assign('order_by', $order_by);
+ }
+
+ # define the result count
+ $smarty->assign('results',$results);
+ $smarty->assign('invoice',$invoice);
+ $smarty->assign('total_amount',$C_list->format_currency($amount,DEFAULT_CURRENCY));
+ }
+
+ public function task_overdue() {
+ $db = &DB();
+
+ $rs = $db->Execute($q=sqlSelect($db,array('invoice','account'),'A.id,A.account_id,SUM(A.total_amt-A.billed_amt) as total,B.first_name,B.last_name,A.due_date',sprintf('A.status=1 AND A.total_amt-A.billed_amt>0 AND A.account_id=B.id AND A.due_date<%s',time()),false,false,false,'account_id,id'));
+ if ($rs && $rs->RecordCount()) {
+ $body = '';
+ $account_total = 0;
+ $account_id = '';
+ $i = 0;
+ $count = 0;
+ $grand_total = 0;
+ while (! $rs->EOF) {
+ if ($account_id != $rs->fields['account_id'] && $i) {
+ $body .= sprintf("Total: %3.2f\n\n",$account_total);
+ $account_total = 0;
+ $i = 0;
+ }
+
+ if (! $i)
+ $body .= sprintf("%s %s (%s)\n",$rs->fields['last_name'],$rs->fields['first_name'],$rs->fields['account_id']);
+
+ $body .= sprintf(" Invoice: %s, Due Date: %s, Amount: %3.2f\n",$rs->fields['id'],date('Y-m-d',$rs->fields['due_date']),$rs->fields['total']);
+ $account_total += $rs->fields['total'];
+ $grand_total += $rs->fields['total'];
+ $account_id = $rs->fields['account_id'];
+ $count++;
+ $i++;
+ $rs->MoveNext();
+ }
+
+ if ($account_total)
+ $body .= sprintf("Total: %3.2f\n",$account_total);
+
+ $body .= "\n";
+
+ if ($count || $ground_total)
+ $body .= sprintf("%3.2f outstanding in %s invoices\n",$grand_total,$count);
+
+ # Send the e-mail....
+ require_once(PATH_INCLUDES.'phpmailer/class.phpmailer.php');
+ $mail = new PHPMailer();
+
+ $mail->AddAddress('deon@leenooks.vpn','Deon George');
+ $mail->From = SITE_EMAIL;
+ $mail->FromName = SITE_NAME;
+ $mail->Subject = 'Overdue invoices';
+ $mail->Body = $body;
+ $mail->Send();
}
}
-
+ /**
+ * Get a list of unpaid invoices for an account
+ */
+ public function unpaid($account_id) {
+ $db = &DB();
+ $invoices = array();
+ $rs = $db->Execute($q=sqlSelect($db,'invoice','id,SUM(total_amt-billed_amt) as total',array('account_id'=>$account_id,'billing_status'=>0,'refund_status'=>0),false,false,'','id'));
+
+ if ($rs && $rs->RecordCount()) {
+ while (! $rs->EOF) {
+ $invoices[$rs->fields['id']] = $rs->fields['total'];
+ $rs->MoveNext();
+ }
+ }
+
+ return $invoices;
+ }
+
/**
* Get the account level invoice options
*
* @param int $id Account Id
*/
- function setupAccount() {
- if(!$this->account_id) return;
- $db=&DB();
- $acctrs=$db->Execute(sqlSelect($db,"account","invoice_grace,invoice_advance_gen","id=$this->account_id"));
- if($acctrs && $acctrs->RecordCount()) {
- $this->advance_gen=$acctrs->fields['invoice_advance_gen'];
- if($this->grace_period == GRACE_PERIOD && !empty($acctrs->fields['invoice_grace'])) $this->grace_period=$acctrs->fields['invoice_grace'];
- }
- }
-
+ private function setupAccount() {
+ if (! $this->account_id)
+ return;
+
+ $db = &DB();
+ $acctrs = $db->Execute(sqlSelect($db,'account','invoice_grace,invoice_advance_gen',sprintf('id=%s',$this->account_id)));
+ if ($acctrs && $acctrs->RecordCount()) {
+ $this->advance_gen = $acctrs->fields['invoice_advance_gen'];
+
+ if ($this->grace_period == GRACE_PERIOD && ! empty($acctrs->fields['invoice_grace']))
+ $this->grace_period = $acctrs->fields['invoice_grace'];
+ }
+ }
+
+ /**
+ * Return the invoice ID
+ */
+ public function getInvoiceID() {
+ return sprintf('%02s-%06s-%06s',DEFAULT_SITE,$this->print['account']['id'],$this->getInvoiceNum());
+ }
+
+ public function getInvoiceNum() {
+ return $this->print['invoice']['id'];
+ }
+
+ public function getPreviousBalance() {
+ static $bal = 0;
+
+ if ($bal)
+ return $bal;
+
+ foreach ($this->print['previousinvoices'] as $item)
+ $bal += $item['total_amt']-$item['billed_amt'];
+
+ return $bal;
+ }
+
/**
* Initialize new invoice creation
*
* @param bool $type 0=new 1=recur
*/
- function initNew($type=0) {
- $this->type=$type;
- $this->date_orig=time();
- $this->date_last=time();
-
+ public function initNew($type=0) {
+ $this->type = $type;
+ $this->date_orig = time();
+ $this->date_last = time();
+
global $C_list;
- $this->net_term = $C_list->is_installed('net_term');
-
- // get account invoice defaults
- $this->setupAccount();
+ $this->net_term = $C_list->is_installed('net_term');
}
-
+
+/** HERE **/
/**
* Commit the current invoice/items/discounts/taxes
*
* @param object $taxObj Object for Tax Calculation
- * @param object $discountObj Object for Discount Calculation
- * @param bool $email Send customer/admin e-mails
+ * @param object $discountObj Object for Discount Calculation
+ * @param bool $email Send customer/admin e-mails
*/
function commitNew(&$taxObj, &$discountObj, $email=true) {
-
- // init DB transaction
- $db=&DB();
+ # init DB transaction
+ $db = &DB();
$db->BeginTrans();
-
- // get invoice id
- if(empty($this->record_id)) $this->record_id = sqlGenID($db,"invoice");
-
- // serialized records:
- if(is_array($this->checkout_plugin_data)) $this->checkout_plugin_data=serialize($this->checkout_plugin_data);
- if(is_array($this->recur_arr)) $this->recur_arr=serialize($this->recur_arr);
-
- // dates & defaults
- if(empty($this->due_date)) $this->due_date=time();
- if(empty($this->date_orig)) $this->date_orig=time();
- if(empty($this->date_last)) $this->date_last=time();
- if(empty($this->notice_next_date)) $this->notice_next_date=$this->due_date+86400;
-
- // net terms
- if ($this->net_term && !$this->billing_status && $this->total_amt>0) {
+
+ # Get invoice id
+ if (empty($this->record_id))
+ $this->record_id = sqlGenID($db,'invoice');
+
+ # Serialized records:
+ if (is_array($this->checkout_plugin_data))
+ $this->checkout_plugin_data=serialize($this->checkout_plugin_data);
+ if (is_array($this->recur_arr))
+ $this->recur_arr=serialize($this->recur_arr);
+
+ # Dates & defaults
+ if (empty($this->due_date))
+ $this->due_date = time();
+ if (empty($this->date_orig))
+ $this->date_orig = time();
+ if (empty($this->date_last))
+ $this->date_last = time();
+ if (empty($this->notice_next_date))
+ $this->notice_next_date = $this->due_date+86400;
+
+ # net terms
+ if ($this->net_term && ! $this->billing_status && $this->total_amt>0) {
include_once(PATH_MODULES.'net_term/net_term.inc.php');
- $net=new net_term;
+ $net = new net_term;
+
$this->net_term_id = $net->termsAllowed($this->account_id, $this->checkout_plugin_id);
- if(empty($this->net_term_date_last)) $this->net_term_date_last=time();
- }
-
- // insert invoice
- $fields=Array(
+ if (empty($this->net_term_date_last))
+ $this->net_term_date_last = time();
+ }
+
+ # Insert invoice
+ $fields=array(
'date_orig'=>$this->date_orig,
- 'date_last'=>$this->date_last,
- 'parent_id'=>$this->parent_id,
- 'type'=>$this->type,
- 'process_status'=>$this->process_status,
- 'billing_status'=>$this->billing_status,
- 'suspend_billing'=>$this->suspend_billing,
- 'refund_status'=>$this->refund_status,
- 'print_status'=>$this->print_status,
- 'account_id'=>$this->account_id,
- 'account_billing_id'=>$this->account_billing_id,
- 'affiliate_id'=>$this->affiliate_id,
- 'campaign_id'=>$this->campaign_id,
- 'reseller_id'=>$this->reseller_id,
- 'checkout_plugin_id'=>$this->checkout_plugin_id,
+ 'date_last'=>$this->date_last,
+ 'parent_id'=>$this->parent_id,
+ 'type'=>$this->type,
+ 'process_status'=>$this->process_status,
+ 'billing_status'=>$this->billing_status,
+ 'suspend_billing'=>$this->suspend_billing,
+ 'refund_status'=>$this->refund_status,
+ 'print_status'=>$this->print_status,
+ 'account_id'=>$this->account_id,
+ 'account_billing_id'=>$this->account_billing_id,
+ 'affiliate_id'=>$this->affiliate_id,
+ 'campaign_id'=>$this->campaign_id,
+ 'reseller_id'=>$this->reseller_id,
+ 'checkout_plugin_id'=>$this->checkout_plugin_id,
'checkout_plugin_data'=>$this->checkout_plugin_data,
- 'tax_amt'=>$this->tax_amt,
- 'discount_amt'=>$this->discount_amt,
- 'total_amt'=>$this->total_amt,
- 'billed_amt'=>$this->billed_amt,
- 'recur_amt'=>$this->recur_amt,
- 'recur_arr'=>$this->recur_arr,
- 'actual_billed_amt'=>$this->actual_billed_amt,
- 'billed_currency_id'=>$this->billed_currency_id,
- 'actual_billed_currency_id'=>$this->actual_billed_currency_id,
- 'notice_count'=>$this->notice_count,
- 'notice_max'=>$this->notice_max,
+ 'tax_amt'=>$this->tax_amt,
+ 'discount_amt'=>$this->discount_amt,
+ 'total_amt'=>$this->total_amt,
+ 'billed_amt'=>$this->billed_amt,
+ 'recur_amt'=>$this->recur_amt,
+ 'recur_arr'=>$this->recur_arr,
+ 'actual_billed_amt'=>$this->actual_billed_amt,
+ 'billed_currency_id'=>$this->billed_currency_id,
+ 'actual_billed_currency_id'=>$this->actual_billed_currency_id,
+ 'notice_count'=>$this->notice_count,
+ 'notice_max'=>$this->notice_max,
'notice_next_date'=>$this->notice_next_date,
- 'due_date'=>$this->due_date,
- 'grace_period'=>$this->grace_period,
- 'net_term_id'=>$this->net_term_id,
- 'net_term_date_last'=>$this->net_term_date_last,
- 'net_term_intervals'=>$this->net_term_intervals,
- 'ip'=>$this->ip
+ 'due_date'=>$this->due_date,
+ 'grace_period'=>$this->grace_period,
+ 'net_term_id'=>$this->net_term_id,
+ 'net_term_date_last'=>$this->net_term_date_last,
+ 'net_term_intervals'=>$this->net_term_intervals,
+ 'ip'=>$this->ip
);
- $db->Execute($sql=sqlInsert($db, "invoice", $fields, $this->record_id));
-
- // loop through invoice items
- if(is_array($this->invoice_item)) {
- foreach($this->invoice_item as $id=>$fields) {
- // get an invoice_item id
- $invoice_item_id = sqlGenID($db, "invoice_item");
-
- // domain sku's
+ $db->Execute(sqlInsert($db,'invoice',$fields,$this->record_id));
+
+ # Loop through invoice items
+ if (is_array($this->invoice_item)) {
+ foreach ($this->invoice_item as $id=>$fields) {
+ # Get an invoice_item id
+ $invoice_item_id = sqlGenID($db,'invoice_item');
+
+ # Domain sku's
if ($fields['item_type'] == 2) {
- $fields['sku'] = "DOMAIN-".strtoupper($fields['domain_type']);
+ $fields['sku'] = sprintf('DOMAIN-%s',strtoupper($fields['domain_type']));
$fields['price_type'] = '0';
}
-
- // build e-mail item details
- if($email) {
- $email_instructions='';
- if($fields['item_type']<2 && !empty($fields['product_id'])) {
+
+ # Build e-mail item details
+ if ($email) {
+ $email_instructions = '';
+
+ if ($fields['item_type']<2 && !empty($fields['product_id'])) {
// product, get email instructions and translated name
- $translate_prod=$db->Execute(sqlSelect($db,"product_translate","email_template,name","product_id={$fields['product_id']} and language_id=::".SESS_LANGUAGE."::"));
- if($translate_prod && $translate_prod->RecordCount()) {
+ $translate_prod = $db->Execute(
+ sqlSelect($db,'product_translate','email_template,name',array('product_id'=>$fields['product_id'],'language_id'=>SESS_LANGUAGE)));
+
+ if ($translate_prod && $translate_prod->RecordCount()) {
$instructions=$translate_prod->fields['email_template'];
$name=$translate_prod->fields['name'];
+
} else {
- $name=$fields["sku"];
+ $name = $fields['sku'];
}
- } elseif ($fields['item_type'] == 2) {
+
+ } elseif ($fields['item_type'] == 2) {
$name=strtoupper($fields['domain_name'].".".$fields['domain_tld']);
+
} else {
- if(!empty($fields['product_name'])) $name=$fields['product_name']; else $name=$fields['sku'];
+ if (! empty($fields['product_name']))
+ $name = $fields['product_name'];
+ else
+ $name = $fields['sku'];
}
- // add to e-mail array
- $email_arr[] = array('Qty' => '('.$fields["quantity"].')', 'Item' => 'SKU '.$fields["sku"], 'Price' => number_format($fields["total_amt"],2), 'Name' => $name, 'Instructions' => $instructions);
- }
-
- // insert the invoice item_id
+
+ // add to e-mail array
+ $email_arr[] = array('Qty' => '('.$fields["quantity"].')', 'Item' => 'SKU '.$fields["sku"], 'Price' => number_format($fields["total_amt"],2), 'Name' => $name, 'Instructions' => $instructions);
+ }
+
+ // insert the invoice item_id
$fields['invoice_id']=$this->record_id;
$fields['date_orig']=time();
$attr = serialize($fields['product_attr']);
$fields['product_attr']=$fields['product_attr_cart'];
- $fields['product_attr_cart']=$attr;
- $db->Execute($sql=sqlInsert($db, "invoice_item", $fields, $invoice_item_id));
-
+ $fields['product_attr_cart']=$attr;
+ $db->Execute(sqlInsert($db,'invoice_item',$fields,$invoice_item_id));
+
+ # Load tax object for tax calculation
+ include_once(PATH_MODULES.'tax/tax.inc.php');
+ $taxObj = new tax;
+
+ # Load discount object for discount calculation
+ include_once(PATH_MODULES.'discount/discount.inc.php');
+ $discountObj = new discount;
+ $discountObj->available_discounts($this->account_id);
+
// insert taxes
- if($this->tax && $this->tax_amt > 0 && !empty($this->tax_arr[$id])) {
- $taxObj->invoice_item($this->record_id, $invoice_item_id, $this->account_id, $this->tax_arr[$id]);
- }
-
+ if ($this->tax && $this->tax_amt > 0 && ! empty($this->tax_arr[$id]))
+ $taxObj->invoice_item($this->record_id,$invoice_item_id,$this->account_id,$this->tax_arr[$id]);
+
// insert discounts
- if($this->discount && $this->discount_amt>0 && !empty($this->discount_arr[$id])) {
- $discountObj->invoice_item($this->record_id, $invoice_item_id, $this->account_id, $this->discount_arr[$id]);
- }
+ if($this->discount && $this->discount_amt>0 && !empty($this->discount_arr[$id]))
+ $discountObj->invoice_item($this->record_id, $invoice_item_id, $this->account_id, $this->discount_arr[$id]);
}
}
-
+
// complete DB transaction
$db->CompleteTrans();
-
+
// complete building e-mail notices and send
- if($email) {
+ if ($email) {
include_once(PATH_MODULES.'email_template/email_template.inc.php');
-
+
// Create the products order list for the e-mail:
$e_itm_usr = '';
$e_itm_adm = '';
@@ -348,28 +614,28 @@ class invoice
foreach($email_arr as $i=>$em) {
$e_itm_usr .= $em['Qty'].' '.$em['Item'].' ('.$em['Name'].') '.$em['Price'];
$e_itm_adm .= $em['Qty'].' '.$em['Item'].' ('.$em['Name'].') '.$em['Price']."\r\n";
- if(!empty($email_arr[$i]['Instructions'])) $e_itm_usr .= "\r\n * " . $email_item_arr[$i]['Instructions'];
- $e_itm_usr .= "\r\n";
- }
- $e_arr_user = Array('%products%' => $e_itm_usr);
- $e_arr_adm = Array('%products%' => $e_itm_adm);
+ if(!empty($email_arr[$i]['Instructions'])) $e_itm_usr .= "\r\n * " . $email_item_arr[$i]['Instructions'];
+ $e_itm_usr .= "\r\n";
+ }
+ $e_arr_user = array('%products%' => $e_itm_usr);
+ $e_arr_adm = array('%products%' => $e_itm_adm);
}
-
- // e-mail invoice creation confirmation
+
+ // e-mail invoice creation confirmation
$mail = new email_template;
- $mail->send('invoice_confirm_user', $this->account_id, $this->record_id, $this->checkout_plugin_id, $e_arr_user);
+ $mail->send('invoice_confirm_user', $this->account_id, $this->record_id, $this->checkout_plugin_id, $e_arr_user);
$email = new email_template;
- $email->send('admin->invoice_confirm_admin', $this->account_id, $this->record_id, $this->checkout_plugin_id, $e_arr_adm);
+ $email->send('admin->invoice_confirm_admin', $this->account_id, $this->record_id, $this->checkout_plugin_id, $e_arr_adm);
}
-
+
// net terms?
if($this->net_term_id) {
- $this->approveInvoice(array('id'=>$this->record_id), $this);
+ $this->approveInvoice(array('id'=>$this->record_id), $this);
return $this->record_id;
- }
-
+ }
+
// Determine the approval status by checkout plugin type & settings:
- if($email && $this->billing_status == 0 && $this->billed_amt > 0 ) {
+ if($email && $this->billing_status == 0 && $this->billed_amt > 0) {
global $C_list;
if($this->checkout_type == 'redirect') {
// User e-mail alert of due invoice
@@ -380,7 +646,7 @@ class invoice
$email = new email_template;
$email->send('admin->invoice_due_admin', $this->account_id, $this->record_id, $admin_currency, $C_list->date($this->due_date));
}
- } elseif($this->billed_amt>0 ) {
+ } elseif($this->billed_amt>0) {
if($email) {
// User alert of payment processed
$email = new email_template;
@@ -390,196 +656,230 @@ class invoice
$email->send('admin->invoice_paid_admin', $this->account_id, $this->record_id, $this->billed_currency_id, '');
}
$this->autoApproveInvoice($this->record_id);
- } elseif($this->billed_amt == 0 && $this->billing_status == 1 ) {
+ } elseif($this->billed_amt == 0 && $this->billing_status == 1) {
$this->autoApproveInvoice($this->record_id);
}
-
+
// return invoice id
return $this->record_id;
}
-
+
/**
* Add an invoice item
*
* @param int $id Reference ID for use in Cart or false
- * @param object $taxObj Object for Tax Calculation
- * @param object $discountObj Object for Discount Calculation
- * @param int $item_type 0/1=Product/Service/Hosting 2=Domain 3=Add Hoc
- * @param string $taxable True, False, or 'validate' to locate the specified $product id and verify
- * @param int $service_id If this is for a service upgrade, this will be defined
- * @param int $parent_id Item Parent Id
- * @param int $product_id Item Product Id
- * @param array $product_attr Item attributes from the cart/prev service
- * @param string $product_name Item product name
- * @param string $sku Item Product SKU
- * @param int $quantity Item Quantity
- * @param float $price_base Item Base price
- * @param float $price_setup Item Setup Price
- * @param float $discount_manual Ad Hoc Discount Amount
- * @param int $recurring_schedule Item recurring schedule, 0=week, 1=month, 2=quarter, 3=semi-annual, 4=annual, 5=bi-year
- * @param int $date_start Date service started
- * @param int $date_stop Date service stops
- * @param string $domain_name Domain name
- * @param string $domain_tld Domain TLD
- * @param int $domain_term Domain Term
- * @param string $domain_type Domain Type (register, transfer, renew, park, ns_transfer)
+ * @param object $cartrs RS from cart query
*/
- function addItem($id, &$taxObj, &$discountObj, $item_type, $taxable=false, $service_id=false, $parent_id=false, $product_id=false, $product_attr=false, $product_name=false, $sku=false, $quantity=1, $price_base=false, $price_setup=false, $discount_manual=false, $recurring_schedule=false, $date_start=false, $date_stop=false, $domain_name=false, $domain_tld=false, $domain_term=false, $domain_type=false) {
- $tax_amt=0;
- $total_amt=0;
- $discount_amt=0;
-
- // define correct qty
- if($quantity<=0) $quantity=1;
-
- // determine the reference id for this item
- if($id>0) {
- $this->item_id=$id;
+ public function addItem($id,$cartrs) {
+ # Setup Variables
+ $item_type = $cartrs->fields['cart_type'];
+ $product_id = $cartrs->fields['product_id'];
+ $recurring_schedule = $cartrs->fields['recurr_schedule'];
+ $domain_tld = $cartrs->fields['domain_tld'];
+ $domain_term = $cartrs->fields['domain_term'];
+ $domain_type = $cartrs->fields['domain_type'];
+
+ # Define correct qty
+ if ($cartrs->fields['quantity']<0)
+ $quantity = 1;
+ else
+ $quantity = $cartrs->fields['quantity'];
+
+ if (! empty($cartrs->fields['product_attr']) && ! is_array($cartrs->fields['product_attr']))
+ $product_attr = unserialize($result->fields['product_attr']);
+ else
+ $product_attr = array();
+
+ # Special processing for ADHOC items
+ if ($item_type == 3) {
+ $taxable = $cartrs->fields['cart_type'];
+ $product_name = $cartrs->fields['ad_hoc_name'];
+ $sku = $cartrs->fields['ad_hoc_sku'];
+ $price_base = $cartrs->fields['ad_hoc_amount'];
+ $price_setup = $cartrs->fields['ad_hoc_setup'];
+ $discount_manual = $cartrs->fields['ad_hoc_discount'];
+
} else {
+ $taxable = false;
+ $product_name = '';
+ $sku = '';
+ $price_base = false;
+ $price_setup = false;
+ $discount_manual = false;
+ }
+
+ $tax_amt = 0;
+ $total_amt = 0;
+ $discount_amt = 0;
+ $item = null;
+
+ # Load tax object for tax calculation
+ include_once(PATH_MODULES.'tax/tax.inc.php');
+ $taxObj = new tax;
+
+ # Load discount object for discount calculation
+ include_once(PATH_MODULES.'discount/discount.inc.php');
+ $discountObj = new discount;
+ $discountObj->available_discounts($this->account_id);
+
+ # Determine the reference id for this item
+ if ($id>0)
+ $this->item_id=$id;
+ else
$this->item_id++;
- }
-
- // get the product details
- if($product_id && $item_type<2) {
- $db=&DB();
- $product=$db->Execute(sqlSelect($db,"product","*","id=$product_id"));
- if($product && $product->RecordCount()) {
- $taxable = $product->fields['taxable'];
- $this->product["$this->item_id"] = $product->fields;
- }
-
- // get the tld details
- } elseif($item_type==2) {
- $db=&DB();
- $tld=$db->Execute(sqlSelect($db,"host_tld","*","name=::$domain_tld::"));
- if($tld && $tld->RecordCount())
- $taxable = $tld->fields['taxable'];
- }
-
- // get the product pricing details if product
- $price_type=0;
- if($price_base===false && $price_setup===false && $product_id && $item_type<2) {
- if($product && $product->RecordCount()) {
- $price_type=$product->fields['price_type'];
- $sku=$product->fields['sku'];
- include_once(PATH_MODULES.'product/product.inc.php');
- $productObj=new product;
- // get pricing for this product:
- $prod_price = $productObj->price_prod($product->fields, $recurring_schedule, $this->account_id);
- $price_base = $prod_price["base"];
- $price_setup = $prod_price["setup"];
-
- // calculate any product attributes fees
- $attr_price = $productObj->price_attr($product->fields, $product_attr, $recurring_schedule, $this->account_id);
- $price_base += $attr_price["base"];
- $price_setup += $attr_price["setup"];
+ if ($product_id) {
+ include_once(PATH_MODULES.'product/product.inc.php');
+ $item_object = new product;
- // determine price type for checkout
- if ($product->fields["price_type"] == '0')
- $this->any_new=true;
- else if ($product->fields["price_type"] == '1')
- $this->any_recurring=true;
- else if ($product->fields["price_type"] == '2')
- $this->any_trial=true;
-
- } else {
- $this->any_new=true;
- }
- } else {
- $this->any_new=true;
+ $item = $item_object->getID($product_id);
+ $this->product[$this->item_id] = $item;
}
-
- // get the TLD pricing details if domain
- if($price_base===false && $price_setup===false && $domain_tld && $domain_term && $domain_type) {
- include_once(PATH_MODULES.'host_tld/host_tld.inc.php');
- $tldObj = new host_tld;
- $tldprice = $tldObj->price_tld_arr($domain_tld, $domain_type, false, false, false, $this->account_id);
- if($domain_type == "park") {
- $price_base = $tldprice;
- } else {
- $price_base = $tldprice["$domain_term"];
- $this->tld_arr["$this->item_id"] = $tldprice;
- }
+
+ switch ($item_type) {
+ # Get the tld details
+ case '2':
+ include_once(PATH_MODULES.'host_tld/host_tld.inc.php');
+ $item_object = new host_tld;
+
+ $item = $item_object->getName($domain_tld);
+
+ # Get the TLD pricing
+ if ($price_base===false && $price_setup===false && $domain_tld && $domain_term && $domain_type) {
+ $tldprice = $item_object->price_tld_arr($domain_tld,$domain_type,false,false,false,$this->account_id);
+
+ if ($domain_type == 'park') {
+ $price_base = $tldprice;
+ } else {
+ $price_base = $tldprice[$domain_term];
+ $this->tld_arr[$this->item_id] = $tldprice;
+ }
+ }
+
+ $price_recur = $price_base;
+
+ break;
+
+ default:
+ # Get the product pricing
+ $price_type = 0;
+ if ($price_base===false && $price_setup===false && $this->product[$this->item_id]) {
+ $price_type = $this->product[$this->item_id]['price_type'];
+ $sku = $this->product[$this->item_id]['sku'];
+
+ # Get pricing for this product:
+ $prod_price = $item_object->price_prod($this->product[$this->item_id],$recurring_schedule,$this->account_id);
+ $price_base = $prod_price['base'];
+ $price_setup = $prod_price['setup'];
+
+ $prod_price = $item_object->price_prod($this->product[$this->item_id],$recurring_schedule,$this->account_id,false);
+ $price_recur = $prod_price['base'];
+
+ # Calculate any product attributes fees
+ $attr_price = $item_object->price_attr($this->product[$this->item_id],$product_attr,$recurring_schedule,$this->account_id);
+ $price_base += $attr_price['base'];
+ $price_setup += $attr_price['setup'];
+ # @todo this cant be the right value for recurring addons?
+ $price_recur += $attr_price['base'];
+
+ # Determine price type for checkout
+ switch ($price_type) {
+ case 0: $this->any_new = true; break;
+ case 1: $this->any_recurring = true; break;
+ case 2: $this->any_trial = true; break;
+ }
+
+ } else {
+ $this->any_new = true;
+ $price_recur = $price_base;
+ }
+
+ break;
}
-
- // set total amount for this line item before attributes, taxes, or discounts
+
+ if ($item && isset($item['taxable']))
+ $taxable = $item['taxable'];
+
+ # Set total amount for this line item before attributes, taxes, or discounts
$price_base *= $quantity;
$price_setup *= $quantity;
- $total_amt = ($price_setup + $price_base);
-
- // format product attributes for storage
- $product_attr_cart=false;
- if(($item_type==0 || $item_type>2) && is_array($product_attr)) $product_attr_cart = $this->get_product_attr_cart($product_attr);
-
- // recurring taxes and arrays
- if($price_base>0 && $price_type==1)
- {
- // increment the total invoice recurring amount
- $this->recur_amt += $price_base;
-
- // determine taxes for the recurring amount
- if($this->tax && $taxable && $price_base>0 && $this->account_id) {
- $recur_tax_arr = $taxObj->calculate($price_base, $this->country_id, $this->state);
- if(is_array($recur_tax_arr)) foreach($recur_tax_arr as $tx) $this->recur_amt += $tx['rate'];
- }
-
- // get the recurring arrays for price and invoice
- if($product && $product->RecordCount()) {
- $this->price_arr["$this->item_id"] = $productObj->price_recurr_arr($product->fields, $this->account_id);
- $this->recur_arr[] = Array (
+ $total_amt = ($price_setup+$price_base);
+
+//echo '';print_r(array('q'=>$quantity,'pb'=>$price_base,'pt'=>$price_type,'pr'=>$price_recur,'id'=>$id,'iid'=>$this->item_id,'p'=>$product->fields));
+
+ # Format product attributes for storage
+ $product_attr_cart = false;
+ if (($item_type==0 || $item_type>2) && is_array($product_attr))
+ $product_attr_cart = $this->get_product_attr_cart($product_attr);
+
+ # Recurring taxes and arrays
+ if (($price_recur || $price_base) && $price_type==1) {
+ $this->recur_amt += $price_recur;
+
+ # Determine taxes for the recurring amount
+ if ($this->tax && $taxable && $price_recur>0 && $this->account_id) {
+ $recur_tax_arr = $taxObj->calculate($price_recur,$this->country_id,$this->state);
+ if (is_array($recur_tax_arr))
+ foreach ($recur_tax_arr as $tx)
+ $this->recur_amt += $tx['rate'];
+ }
+
+ # Get the recurring arrays for price and invoice
+ if ($item_object) {
+ $this->price_arr[$this->item_id] = $item_object->price_recurr_arr($this->product[$this->item_id],$this->account_id);
+ $this->recur_arr[] = array(
'price' => $price_base*$quantity,
'recurr_schedule'=> $recurring_schedule,
- 'recurr_type' => $product->fields['price_recurr_type'],
- 'recurr_weekday' => $product->fields['price_recurr_weekday'],
- 'recurr_week' => $product->fields['price_recurr_week']
- );
- }
+ 'recurr_type' => $this->product[$this->item_id]['price_recurr_type'],
+ 'recurr_weekday' => $this->product[$this->item_id]['price_recurr_weekday'],
+ 'recurr_week' => $this->product[$this->item_id]['price_recurr_week']
+ );
+ }
}
-
- // calculate any ad-hoc line item level (admin) discounts
- if($this->discount && $discount_manual>0) {
+
+ # Calculate any ad-hoc line item level (admin) discounts
+ if ($this->discount && $discount_manual>0) {
$total_amt -= $discount_manual;
$discount_amt += $discount_manual;
- $this->discount_amt += $discount_amt;
+ $this->discount_amt += $discount_amt;
$discountObj->add_manual_discount($discount_manual,'MISC',$this->item_id);
}
-
- // account level discounts
- if($this->discount && $this->account_id) {
- // calculate any database level discounts for this item (both account specific and session specific)
- $discount_amt = $discountObj->calc_all_discounts(0, $this->item_id, $product_id, $total_amt, $this->account_id, $this->total_amt+$total_amt);
- $total_amt -= $discount_amt;
- $this->discount_amt += $discount_amt;
+
+ # Account level discounts
+ if ($this->discount && $this->account_id) {
+ # Calculate any database level discounts for this item (both account specific and session specific)
+ $discount_amt = $discountObj->calc_all_discounts(0,$this->item_id,$product_id,$total_amt,$this->account_id,$this->total_amt+$total_amt);
+ $total_amt -= $discount_amt;
+ $this->discount_amt += $discount_amt;
}
-
- // add to total discount array
- if(is_array($discountObj->discount_arr)) {
- $this->discount_arr["$this->item_id"] = $discountObj->discount_arr;
+
+ # Add to total discount array
+ if (is_array($discountObj->discount_arr)) {
+ $this->discount_arr[$this->item_id] = $discountObj->discount_arr;
}
-
- // increment invoice total amount
+
+ # Increment invoice total amount
$this->total_amt += $total_amt;
-
- // calculate any taxes for current item
- if($this->tax && $taxable && $total_amt>0 && $this->account_id) {
- $tax_arr = $taxObj->calculate($total_amt, $this->country_id, $this->state);
+
+ // calculate any taxes for current item
+ if ($this->tax && $taxable && $total_amt>0 && $this->account_id) {
+ $tax_arr = $taxObj->calculate($total_amt, $this->country_id, $this->state);
if(is_array($tax_arr)) {
- foreach($tax_arr as $tx) $tax_amt += $tx['rate'];
- $this->item_tax["$this->item_id"] = $tax_arr;
- $this->tax_arr["$this->item_id"] = $tax_arr;
+ foreach($tax_arr as $tx) $tax_amt += $tx['rate'];
+ $this->item_tax[$this->item_id] = $tax_arr;
+ $this->tax_arr[$this->item_id] = $tax_arr;
}
$this->tax_amt += $tax_amt;
- $this->total_amt += $tax_amt;
+ $this->total_amt += $tax_amt;
}
-
+
// store the fields to an array
- $this->invoice_item["$this->item_id"]=Array(
+ $this->invoice_item[$this->item_id] = array(
'item_type'=>$item_type,
'price_type'=>$price_type,
'taxable'=>$taxable,
- 'service_id'=>$service_id,
- 'parent_id'=>$parent_id,
+ 'service_id'=>$cartrs->fields['service_id'],
+ 'parent_id'=>$cartrs->fields['parent_id'],
'product_id'=>$product_id,
'product_attr'=>$product_attr,
'product_attr_cart'=>$product_attr_cart,
@@ -589,58 +889,58 @@ class invoice
'price_base'=>$price_base,
'price_setup'=>$price_setup,
'recurring_schedule'=>$recurring_schedule,
- 'date_start'=>$date_start,
- 'date_stop'=>$date_stop,
- 'domain_name'=>$domain_name,
+ 'date_start'=>'',
+ 'date_stop'=>'',
+ 'domain_name'=>$cartrs->fields['domain_name'],
'domain_tld'=>$domain_tld,
'domain_term'=>$domain_term,
- 'domain_type'=>$domain_type,
+ 'domain_type'=>$domain_type,
'total_amt'=>$total_amt,
'tax_amt'=>$tax_amt,
'discount_amt'=>$discount_amt
);
}
-
+
/**
* Group all taxes to lump sums
*/
- function group_taxes() {
+ public function group_taxes() {
if(is_array($this->tax_arr)) {
- foreach($this->tax_arr as $taxarr) foreach($taxarr as $taxes) $arr[$taxes["name"]]+=$taxes["rate"];
+ foreach($this->tax_arr as $taxarr) foreach($taxarr as $taxes) $arr[$taxes["name"]]+=$taxes["rate"];
if(is_array($arr)) {
- foreach($arr as $a=>$b) $ret[] = Array('name'=>$a, 'rate'=>$b);
- return $ret;
- }
- }
+ foreach($arr as $a=>$b) $ret[] = array('name'=>$a, 'rate'=>$b);
+ return $ret;
+ }
+ }
}
-
+
/**
* Group all discounts to lump sums
*/
- function group_discounts() {
- if(is_array($this->discount_arr)) {
- foreach($this->discount_arr as $discarr) foreach($discarr as $discounts) $arr[$discounts["discount"]]+=$discounts["amount"];
+ public function group_discounts() {
+ if(is_array($this->discount_arr)) {
+ foreach($this->discount_arr as $discarr) foreach($discarr as $discounts) $arr[$discounts["discount"]]+=$discounts["amount"];
if(is_array($arr)) {
- foreach($arr as $a=>$b) $ret[] = Array('name'=>$a, 'total'=>$b);
- return $ret;
+ foreach($arr as $a=>$b) $ret[] = array('name'=>$a, 'total'=>$b);
+ return $ret;
}
- }
- }
-
+ }
+ }
+
/**
* Build a formatted product attribute list
*
* @param array $attributes
* @return string Formatted product attribute list
*/
- function get_product_attr_cart($attributes) {
+ public function get_product_attr_cart($attributes) {
# Set the attribute array:
if(!empty($attributes) && is_array($attributes)) {
$db=&DB();
- $product_attr = false;
+ $product_attr = false;
foreach($attributes as $id=>$value) {
if (!empty($value)) {
- if(is_numeric($id)) {
+ if(is_numeric($id)) {
$attr = $db->Execute(sqlSelect($db,"product_attr","name","id=$id"));
if ($attr && $attr->RecordCount()) $product_attr .= "{$attr->fields['name']}==".ereg_replace("\r\n", " ", $value)."\r\n";
} else {
@@ -651,95 +951,82 @@ class invoice
}
return $product_attr;
}
-
-
-
- /** Custom Tracking
- */
- function custom_tracking($VAR)
- {
+
+ /**
+ * Custom Tracking
+ * @todo: should this be here, or under the affilate module? what does it do?
+ */
+ public function custom_tracking($VAR) {
# Get the invoice id
- if(SESS_LOGGED == false)
- return false;
+ if (SESS_LOGGED == false)
+ return false;
# Check if we are in the iframe
- if(empty($VAR['_escape']) || empty($VAR['confirm']))
- {
- echo '';
+ if (empty($VAR['_escape']) || empty($VAR['confirm'])) {
+ printf('',
+ md5(microtime()));
return;
}
# Get the un-tracked invoice details
$db = &DB();
- $sql = "SELECT * FROM ".AGILE_DB_PREFIX."invoice WHERE
- ( custom_affiliate_status IS NULL OR
- custom_affiliate_status = 0 )
- AND billing_status = ".$db->qstr(1)."
- AND site_id = ".$db->qstr(DEFAULT_SITE)."
- AND account_id = ".$db->qstr(SESS_ACCOUNT);
- $result = $db->Execute($sql);
+
+ $result = $db->Execute(sqlSelect($db,'invoice','*',sprintf('(custom_affiliate_status IS NULL OR custom_affiliate_status=0) AND billing_status=1 AND account_id=%s',SESS_ACCOUNT)));
if ($result === false) {
global $C_debug;
- $C_debug->error('','', $db->ErrorMsg(). "\r\n\r\n". $sql);
+ $C_debug->error(__FILE__,__METHOD__,sprintf('%s (%s)',$db->ErrorMsg(),$sql));
+
return false;
}
- if($result->RecordCount() == 0) {
- echo 'none';
+
+ if ($result->RecordCount() == 0)
return false;
- }
# Get the totals
$invoice = '';
$total_amount = false;
- while(!$result->EOF)
- {
- if(!empty($invoice))
- $invoice .= '-';
+ while (! $result->EOF) {
+ if (! empty($invoice))
+ $invoice .= '-';
+
$invoice .= $result->fields['id'];
- $amt = $result->fields["total_amt"];
+ $amt = $result->fields['total_amt'];
$total_amount += $amt;
$result->MoveNext();
}
- # echo the custom tracking code to the screen:
- if(!is_file(PATH_FILES.'tracking.txt')) return false;
+ # Echo the custom tracking code to the screen:
+ if (! is_file(PATH_FILES.'tracking.txt'))
+ return false;
+
$tracking = file_get_contents(PATH_FILES.'tracking.txt');
- $tracking = ereg_replace('%%amount%%', "$total_amount", $tracking);
- $tracking = ereg_replace('%%invoice%%', $invoice, $tracking);
- $tracking = ereg_replace('%%affiliate%%', SESS_AFFILIATE, $tracking);
- $tracking = ereg_replace('%%campaign%%', SESS_CAMPAIGN, $tracking);
- $tracking = ereg_replace('%%account%%', SESS_ACCOUNT, $tracking);
+ $tracking = str_replace('%%amount%%',$total_amount,$tracking);
+ $tracking = str_replace('%%invoice%%',$invoice,$tracking);
+ $tracking = str_replace('%%affiliate%%',SESS_AFFILIATE,$tracking);
+ $tracking = str_replace('%%campaign%%',SESS_CAMPAIGN,$tracking);
+ $tracking = str_replace('%%account%%',SESS_ACCOUNT,$tracking);
echo $tracking;
-
+
# Update the record so it is not tracked again
- $sql = "UPDATE ".AGILE_DB_PREFIX."invoice
- SET
- custom_affiliate_status = ".$db->qstr('1')."
- WHERE
- account_id = ".$db->qstr(SESS_ACCOUNT)."
- AND
- billing_status = ".$db->qstr(1)."
- AND
- site_id = ".$db->qstr(DEFAULT_SITE);
- $rs = $db->Execute($sql);
+ $rs = $db->Execute(sqlUpdate($db,'invoice',array('custom_affiliate_status'=>1),sprintf('account_id=%s AND billing_status=1',SESS_ACCOUNT)));
if ($rs === false) {
global $C_debug;
- $C_debug->error('','', $db->ErrorMsg(). "\r\n\r\n". $sql);
+ $C_debug->error(__FILE__,__METHOD__,sprintf('%s (%s)',$db->ErrorMsg(),$sql));
}
+
return true;
}
-
+
/** Performance: (for the admin dashboard)
*/
- function performance($VAR)
+ public function performance($VAR)
{
global $smarty, $C_list, $C_translate;
-
+
# Get the period type, default to month
if (empty($VAR['period']))
$p = 'm';
@@ -747,33 +1034,33 @@ class invoice
$p = $VAR['period'];
# Determine the correct period language:
- if($p=='' or $p == 'm')
+ if($p=='' or $p == 'm')
{
$pTrans = $C_translate->translate('thismonth','invoice','') . ' '.
$C_translate->translate('vs','invoice','') . ' ' .
$C_translate->translate('lastmonth','invoice','');
$pFore = $C_translate->translate('thismonth','invoice','');
- }
- elseif ($p == 'w')
+ }
+ elseif ($p == 'w')
{
$pTrans = $C_translate->translate('thisweek','invoice','') . ' '.
$C_translate->translate('vs','invoice','') . ' ' .
- $C_translate->translate('lastweek','invoice','');
- $pFore = $C_translate->translate('thisweek','invoice','');
+ $C_translate->translate('lastweek','invoice','');
+ $pFore = $C_translate->translate('thisweek','invoice','');
}
- elseif ($p == 'y')
+ elseif ($p == 'y')
{
$pTrans = $C_translate->translate('thisyear','invoice','') . ' '.
$C_translate->translate('vs','invoice','') . ' ' .
- $C_translate->translate('lastyear','invoice','');
+ $C_translate->translate('lastyear','invoice','');
$pFore = $C_translate->translate('thisyear','invoice','');
}
-
+
$smarty->assign('period_compare', $pTrans);
- $smarty->assign('period_forcast', $pFore);
-
-
-
+ $smarty->assign('period_forcast', $pFore);
+
+
+
# Get the period start & end
switch ($p) {
case 'w':
@@ -805,11 +1092,11 @@ class invoice
$db = &DB();
$this_amt = 0;
$sql = 'SELECT total_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- date_orig >= ' . $db->qstr( $this_start ) . ' AND
- date_orig <= ' . $db->qstr( $this_end ) . ' AND
+ date_orig >= ' . $db->qstr($this_start) . ' AND
+ date_orig <= ' . $db->qstr($this_end) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
- while( !$rs->EOF ) {
+ while(!$rs->EOF) {
$this_amt += $rs->fields['total_amt'];
$rs->MoveNext();
}
@@ -820,11 +1107,11 @@ class invoice
###############################
$last_amt = 0;
$sql = 'SELECT total_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- date_orig >= ' . $db->qstr( $last_start ) . ' AND
- date_orig <= ' . $db->qstr( $last_end ) . ' AND
+ date_orig >= ' . $db->qstr($last_start) . ' AND
+ date_orig <= ' . $db->qstr($last_end) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
- while( !$rs->EOF ) {
+ while(!$rs->EOF) {
$last_amt += $rs->fields['total_amt'];
$rs->MoveNext();
}
@@ -880,7 +1167,7 @@ class invoice
###############################
# Get forcast change percentage
###############################
- if($last_amt > 0 )
+ if($last_amt > 0)
@$forcast_change = $forcast_daily/$forcast_1_daily *100;
else
$forcast_change = 0;
@@ -907,12 +1194,12 @@ class invoice
##############################
$this_billed_amt = 0;
$sql = 'SELECT billed_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- date_orig >= ' . $db->qstr( $this_start ) . ' AND
- date_orig <= ' . $db->qstr( $this_end ) . ' AND
- billed_amt > ' . $db->qstr( 0 ) . ' AND
+ date_orig >= ' . $db->qstr($this_start) . ' AND
+ date_orig <= ' . $db->qstr($this_end) . ' AND
+ billed_amt > ' . $db->qstr(0) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
- while( !$rs->EOF ) {
+ while(!$rs->EOF) {
$this_billed_amt += $rs->fields['billed_amt'];
$rs->MoveNext();
}
@@ -923,12 +1210,12 @@ class invoice
###############################
$last_billed_amt = 0;
$sql = 'SELECT billed_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- date_orig >= ' . $db->qstr( $last_start ) . ' AND
- date_orig <= ' . $db->qstr( $last_end ) . ' AND
- billed_amt > ' . $db->qstr( 0 ) . ' AND
+ date_orig >= ' . $db->qstr($last_start) . ' AND
+ date_orig <= ' . $db->qstr($last_end) . ' AND
+ billed_amt > ' . $db->qstr(0) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
- while( !$rs->EOF ) {
+ while(!$rs->EOF) {
$last_billed_amt += $rs->fields['billed_amt'];
$rs->MoveNext();
}
@@ -964,8 +1251,8 @@ class invoice
# Get Users (current)
#########################################
$sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'account WHERE
- date_orig >= ' . $db->qstr( $this_start ) . ' AND
- date_orig <= ' . $db->qstr( $this_end ) . ' AND
+ date_orig >= ' . $db->qstr($this_start) . ' AND
+ date_orig <= ' . $db->qstr($this_end) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
$users_current = $rs->RecordCount();
@@ -975,8 +1262,8 @@ class invoice
# Get Users (previous)
#########################################
$sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'account WHERE
- date_orig >= ' . $db->qstr( $last_start ) . ' AND
- date_orig <= ' . $db->qstr( $last_end ) . ' AND
+ date_orig >= ' . $db->qstr($last_start) . ' AND
+ date_orig <= ' . $db->qstr($last_end) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
$users_previous = $rs->RecordCount();
@@ -999,53 +1286,8 @@ class invoice
$smarty->assign('users_change', $users_change);
- # Get Tickets
- if( $C_list->is_installed('ticket') )
- {
- $smarty->assign('show_tickets', true);
-
- #########################################
- # Get Tickets (current)
- #########################################
- $sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'ticket WHERE
- date_orig >= ' . $db->qstr( $this_start ) . ' AND
- date_orig <= ' . $db->qstr( $this_end ) . ' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $rs = $db->Execute($sql);
- $tickets_current = $rs->RecordCount();
- $smarty->assign('tickets_current', $tickets_current);
-
- #########################################
- # Get Tickets (previous)
- #########################################
- $sql = 'SELECT id FROM ' . AGILE_DB_PREFIX . 'ticket WHERE
- date_orig >= ' . $db->qstr( $last_start ) . ' AND
- date_orig <= ' . $db->qstr( $last_end ) . ' AND
- site_id = ' . $db->qstr(DEFAULT_SITE);
- $rs = $db->Execute($sql);
- $tickets_previous = $rs->RecordCount();
- $smarty->assign('tickets_previous', $tickets_previous);
-
- ###############################
- # Get Tickets change percentage
- ###############################
- if($tickets_previous > 0)
- @$tickets_change = $tickets_current/$tickets_current *100 -100;
- else
- $tickets_change = 0;
-
- if($tickets_change == 0)
- $tickets_change = '-';
- elseif($tickets_change < 0)
- $tickets_change = '' . number_format($tickets_change, 1). '% ';
- else
- $tickets_change = '+'.number_format($tickets_change, 1). '%';
-
- $smarty->assign('tickets_change', $tickets_change);
- }
-
# Get Affiliate stats
- if( $C_list->is_installed('affiliate') )
+ if($C_list->is_installed('affiliate'))
{
$smarty->assign('show_affiliates', true);
@@ -1054,13 +1296,13 @@ class invoice
###########################################
$this_amt = 0;
$sql = 'SELECT total_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- date_orig >= ' . $db->qstr( $this_start ) . ' AND
- date_orig <= ' . $db->qstr( $this_end ) . ' AND
- affiliate_id != ' . $db->qstr( 0 ) . ' AND
- affiliate_id != ' . $db->qstr( '' ) . ' AND
+ date_orig >= ' . $db->qstr($this_start) . ' AND
+ date_orig <= ' . $db->qstr($this_end) . ' AND
+ affiliate_id != ' . $db->qstr(0) . ' AND
+ affiliate_id != ' . $db->qstr('') . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
- while( !$rs->EOF ) {
+ while(!$rs->EOF) {
$this_amt += $rs->fields['total_amt'];
$rs->MoveNext();
}
@@ -1071,13 +1313,13 @@ class invoice
##########################################
$last_amt = 0;
$sql = 'SELECT total_amt FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- date_orig >= ' . $db->qstr( $last_start ) . ' AND
- date_orig <= ' . $db->qstr( $last_end ) . ' AND
- affiliate_id != ' . $db->qstr( 0 ) . ' AND
- affiliate_id != ' . $db->qstr( '' ) . ' AND
+ date_orig >= ' . $db->qstr($last_start) . ' AND
+ date_orig <= ' . $db->qstr($last_end) . ' AND
+ affiliate_id != ' . $db->qstr(0) . ' AND
+ affiliate_id != ' . $db->qstr('') . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
- while( !$rs->EOF ) {
+ while(!$rs->EOF) {
$last_amt += $rs->fields['total_amt'];
$rs->MoveNext();
}
@@ -1100,34 +1342,34 @@ class invoice
$smarty->assign('affiliate_sales_change', $sales_change);
}
-
-
+
+
/** Get VoIP Performance Data
- */
+ */
if( $C_list->is_installed('voip') )
- {
-
+ {
+
# Avg. Call Duration for this period
$rs = $db->Execute(sqlSelect($db, "voip_cdr", "avg(ceiling(billsec/60))", "disposition='ANSWERED' AND date_orig >= $this_start AND date_orig <= $this_end"));
- if(empty($rs->fields[0])) $acd=0; else $acd = $rs->fields[0];
- $smarty->assign('acd',$acd);
-
+ if(empty($rs->fields[0])) $acd=0; else $acd = $rs->fields[0];
+ $smarty->assign('acd',$acd);
+
# Avg. Call Duration for last period
$rs = $db->Execute(sqlSelect($db, "voip_cdr", "avg(ceiling(billsec/60))", "disposition='ANSWERED' AND date_orig >= $last_start AND date_orig <= $last_end"));
- if(empty($rs->fields[0])) $acd_last=0; else $acd_last = $rs->fields[0];
+ if(empty($rs->fields[0])) $acd_last=0; else $acd_last = $rs->fields[0];
$smarty->assign('acd_last',$acd_last);
-
+
# Get Avg. Call Duration change Percentage
if($acd > 0) $acd_change = $acd/$acd_last*100-100; else $acd_change = 0;
- if($acd_change == 0)
+ if($acd_change == 0)
$acd_change = '-';
elseif ($acd_change < 0)
$acd_change = '' . number_format($acd_change, 1). '% ';
- else
+ else
$acd_change = '+'.number_format($acd_change, 1). '%';
$smarty->assign('acd_change', $acd_change);
-
-
+
+
# Avg. Successful Rate for this period
$rs = $db->Execute(sqlSelect($db, "voip_cdr", "count(*)", "disposition='ANSWERED' AND date_orig >= $this_start AND date_orig <= $this_end"));
$rs1 = $db->Execute(sqlSelect($db, "voip_cdr", "count(*)", "date_orig >= $this_start AND date_orig <= $this_end"));
@@ -1135,12 +1377,12 @@ class invoice
$asr = number_format(($rs->fields[0] / $rs1->fields[0]) * 100,3)." %";
else
$asr = "-";
- $smarty->assign('asr', $asr);
-
+ $smarty->assign('asr', $asr);
+
# Number of CDRs for this period
$cdrs = $rs1->fields[0];
- $smarty->assign('cdrs', number_format($cdrs,0));
-
+ $smarty->assign('cdrs', number_format($cdrs,0));
+
# Avg. Successful Rate for last period
$rs = $db->Execute(sqlSelect($db, "voip_cdr", "count(*)", "disposition='ANSWERED' AND date_orig >= $last_start AND date_orig <= $last_end"));
$rs1 = $db->Execute(sqlSelect($db, "voip_cdr", "count(*)", "date_orig >= $last_start AND date_orig <= $last_end"));
@@ -1148,87 +1390,87 @@ class invoice
$asr_last = number_format(($rs->fields[0] / $rs1->fields[0]) * 100,3)." %";
else
$asr_last = "-";
- $smarty->assign('asr_last', $asr_last);
-
+ $smarty->assign('asr_last', $asr_last);
+
# Number of CDRS for last period
$cdrs_last = $rs1->fields[0];
- $smarty->assign('cdrs_last', number_format($cdrs_last,0));
-
+ $smarty->assign('cdrs_last', number_format($cdrs_last,0));
+
# Get Avg. Successful Rate change Percentage
if($asr > 0) $asr_change = $asr/$asr_last*100-100; else $asr_change = 0;
- if($asr_change == 0)
+ if($asr_change == 0)
$asr_change = '-';
elseif ($asr_change < 0)
$asr_change = '' . number_format($asr_change, 1). '% ';
- else
+ else
$asr_change = '+'.number_format($asr_change, 1). '%';
$smarty->assign('asr_change', $asr_change);
-
-
+
+
# Get Number of CDRs change Percentage
if($cdrs > 0) $cdrs_change = $cdrs/$cdrs_last*100-100; else $cdrs_change = 0;
- if($cdrs_change == 0)
+ if($cdrs_change == 0)
$cdrs_change = '-';
elseif ($cdrs_change < 0)
$cdrs_change = '' . number_format($cdrs_change, 1). '% ';
- else
+ else
$cdrs_change = '+'.number_format($cdrs_change, 1). '%';
$smarty->assign('cdrs_change', $cdrs_change);
}
-
-
+
+
# Generate the Calendar Overview
include_once(PATH_MODULES.'core/calendar.inc.php');
- $calendar = new calendar;
+ $calendar = new calendar;
$start = $calendar->start;
- $end = $calendar->end;
-
+ $end = $calendar->end;
+
global $C_list;
$C_list->currency(DEFAULT_CURRENCY);
$currency_symbol=$C_list->format_currency[DEFAULT_CURRENCY]['symbol'];
-
+
# Get the paid/due invoice statistics
$rs = $db->Execute($sql=sqlSelect($db,"invoice","date_orig,total_amt,billing_status,refund_status,billed_amt,suspend_billing","date_orig >= $start and date_orig <= $end"));
- if($rs && $rs->RecordCount()) {
+ if($rs && $rs->RecordCount()) {
while(!$rs->EOF) {
$day = date("j", $rs->fields['date_orig']);
-
- if($rs->fields['billed_amt'] > 0 && ($rs->fields['billing_status'] == 1 || $rs->fields['refund_status'] != 1)) {
+
+ if($rs->fields['billed_amt'] > 0 && ($rs->fields['billing_status'] == 1 || $rs->fields['refund_status'] != 1)) {
$paid[$day] += $rs->fields['billed_amt'];
}
- if ($rs->fields['billing_status'] != 1 && $rs->fields['refund_status'] != 1 ) {
+ if ($rs->fields['billing_status'] != 1 && $rs->fields['refund_status'] != 1) {
$amt = $rs->fields['total_amt'] - $rs->fields['billed_amt'];
$due[$day] += $amt;
- }
-
+ }
+
$rs->MoveNext();
- }
-
+ }
+
if(is_array($paid))
- foreach($paid as $day=>$item)
+ foreach($paid as $day=>$item)
$calendar->add("Paid - {$currency_symbol}". number_format($item,2), $day, 'green', 'green');
-
+
if(is_array($due))
- foreach($due as $day=>$item)
- $calendar->add("Due - {$currency_symbol}". number_format($item,2), $day,'red','red');
+ foreach($due as $day=>$item)
+ $calendar->add("Due - {$currency_symbol}". number_format($item,2), $day,'red','red');
}
-
- # Get the upcoming due services
+
+ # Get the upcoming due services
$rs = $db->Execute($sql=sqlSelect($db,"service","date_next_invoice,price","price > 0 AND date_next_invoice >= $start AND date_next_invoice <= $end AND suspend_billing <> 1"));
- if($rs && $rs->RecordCount()) {
+ if($rs && $rs->RecordCount()) {
while(!$rs->EOF) {
- $day = date("j", $rs->fields['date_next_invoice']);
- $sdue[$day] += $rs->fields['price'];
+ $day = date("j", $rs->fields['date_next_invoice']);
+ $sdue[$day] += $rs->fields['price'];
$rs->MoveNext();
- }
+ }
foreach($sdue as $day=>$item) {
$calendar->add("Recurring - {$currency_symbol}". number_format($item,2), $day, 'grey', 'grey');
- }
- }
-
+ }
+ }
+
$calout= $calendar->generate();
$smarty->assign("calendar", $calout);
-
+
return;
}
@@ -1246,7 +1488,7 @@ class invoice
$invoice = $db->Execute($q);
if ($invoice === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','autoApproveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'autoApproveInvoice', $db->ErrorMsg());
return false;
}
@@ -1257,7 +1499,7 @@ class invoice
$checkout = $db->Execute($q);
if ($checkout === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','autoApproveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'autoApproveInvoice', $db->ErrorMsg());
return false;
}
@@ -1268,17 +1510,17 @@ class invoice
$account = $db->Execute($q);
if ($account === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','autoApproveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'autoApproveInvoice', $db->ErrorMsg());
return false;
}
# is this a recurring invoices, and is manual approvale req?
- if ( $invoice->fields['type'] == 1 && $checkout->fields['manual_approval_recur'] != 1) {
+ if ($invoice->fields['type'] == 1 && $checkout->fields['manual_approval_recur'] != 1) {
$do = true;
}
# Manual approval required for all?
- if( $invoice->fields['type'] != 1 && $checkout->fields['manual_approval_all'] != 1) {
+ if($invoice->fields['type'] != 1 && $checkout->fields['manual_approval_all'] != 1) {
$do = true;
}
@@ -1317,7 +1559,7 @@ class invoice
$groups = $db->Execute($q);
if ($groups === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','autoApproveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'autoApproveInvoice', $db->ErrorMsg());
}
$arr = unserialize($checkout->fields['manual_approval_group']);
@@ -1360,7 +1602,7 @@ class invoice
$invoice = $db->Execute($q);
if ($invoice === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','approveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'approveInvoice', $db->ErrorMsg());
return false;
}
@@ -1376,7 +1618,7 @@ class invoice
$result = $db->Execute($q);
if ($result === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','approveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'approveInvoice', $db->ErrorMsg());
return false;
}
@@ -1390,7 +1632,7 @@ class invoice
$srvc = new service;
# Determine if services have already been created for this invoice:
- if($invoice->fields['type'] != 1 )
+ if($invoice->fields['type'] != 1)
{
$q = "SELECT id FROM ".AGILE_DB_PREFIX."service WHERE
invoice_id = ".$db->qstr($VAR['id'])." AND
@@ -1398,7 +1640,7 @@ class invoice
$service = $db->Execute($q);
if ($service === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','approveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'approveInvoice', $db->ErrorMsg());
return false;
}
if ($service->RecordCount() > 0)
@@ -1414,13 +1656,13 @@ class invoice
# Get the parent items in this invoice :
$q = "SELECT * FROM ".AGILE_DB_PREFIX."invoice_item WHERE
- ( parent_id = 0 OR parent_id IS NULL OR parent_id = '') AND
+ (parent_id = 0 OR parent_id IS NULL OR parent_id = '') AND
invoice_id = ".$db->qstr($VAR['id'])." AND
site_id = ".$db->qstr(DEFAULT_SITE);
$ii = $db->Execute($q);
if ($ii === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','approveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'approveInvoice', $db->ErrorMsg());
return false;
}
while(!$ii->EOF)
@@ -1438,7 +1680,7 @@ class invoice
$iii = $db->Execute($q);
if ($iii === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','approveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'approveInvoice', $db->ErrorMsg());
return false;
}
while(!$iii->EOF)
@@ -1451,18 +1693,18 @@ class invoice
else
{
$srvc = new service;
- if($ii->fields['item_type'] == 2 && $ii->fields['domain_type'] == 'renew' ) {
+ if($ii->fields['item_type'] == 2 && $ii->fields['domain_type'] == 'renew') {
# this is a domain renewal
- $srvc->renewDomain( $ii, $invoice->fields['account_billing_id'] );
+ $srvc->renewDomain($ii, $invoice->fields['account_billing_id']);
} else {
# this is an upgrade for an existing service
- $srvc->modifyService( $ii, $invoice->fields['account_billing_id'] );
+ $srvc->modifyService($ii, $invoice->fields['account_billing_id']);
}
}
$ii->MoveNext();
}
}
- elseif ($invoice->fields['type'] == 1 )
+ elseif ($invoice->fields['type'] == 1)
{
# recurring invoice, just update assoc services
# Loop through invoice items & approve assoc services
@@ -1472,7 +1714,7 @@ class invoice
$service = $db->Execute($q);
if ($service === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','voidInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'voidInvoice', $db->ErrorMsg());
return false;
}
if ($service->RecordCount() > 0)
@@ -1509,7 +1751,7 @@ class invoice
$memo = $db->Execute($q);
if ($memo === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','approveInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'approveInvoice', $db->ErrorMsg());
return false;
}
return true;
@@ -1530,7 +1772,7 @@ class invoice
$update = $db->Execute($q);
if ($update === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','voidInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'voidInvoice', $db->ErrorMsg());
return false;
}
@@ -1541,7 +1783,7 @@ class invoice
$service = $db->Execute($q);
if ($service === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','voidInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'voidInvoice', $db->ErrorMsg());
return false;
}
if ($service->RecordCount() > 0)
@@ -1564,7 +1806,7 @@ class invoice
$service = $db->Execute($q);
if ($service === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','voidInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'voidInvoice', $db->ErrorMsg());
return false;
}
if ($service->RecordCount() > 0)
@@ -1578,7 +1820,7 @@ class invoice
$srvc->voidService($service->fields['service_id']);
$service->MoveNext();
}
- }
+ }
# if voided, create a memo
$id = $db->GenID(AGILE_DB_PREFIX . 'invoice_memo_id');
@@ -1594,7 +1836,7 @@ class invoice
$insert = $db->Execute($q);
if ($insert === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','voidInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'voidInvoice', $db->ErrorMsg());
return false;
}
return true;
@@ -1608,20 +1850,20 @@ class invoice
global $C_translate, $C_debug;
# validate amt
- if( $VAR['amount'] <= 0) {
- $C_debug->alert( "Payment amount to low!" );
+ if($VAR['amount'] <= 0) {
+ $C_debug->alert("Payment amount to low!");
return false;
}
# get the invoice details
$db = &DB();
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- id = ' . $db->qstr( $VAR['id'] ) . ' AND
+ id = ' . $db->qstr($VAR['id']) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
if ($rs === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','reconcileInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'reconcileInvoice', $db->ErrorMsg());
return false;
}
@@ -1660,13 +1902,13 @@ class invoice
# Update the invoice record
$sql = 'UPDATE ' . AGILE_DB_PREFIX . 'invoice
SET
- billed_amt = ' . $db->qstr( $update ) . ',
- billing_status = ' . $db->qstr( $billed ) . '
+ billed_amt = ' . $db->qstr($update) . ',
+ billing_status = ' . $db->qstr($billed) . '
WHERE
- id = ' . $db->qstr( $VAR['id'] ) . ' AND
+ id = ' . $db->qstr($VAR['id']) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$db->Execute($sql);
-
+
# Create a memo
$id = $db->GenID(AGILE_DB_PREFIX . 'invoice_memo_id');
$q = "INSERT INTO ".AGILE_DB_PREFIX."invoice_memo
@@ -1679,13 +1921,13 @@ class invoice
type = ".$db->qstr('reconcile').",
memo = ".$db->qstr('+ '.number_format($VAR['amount'],2) . " \r\n" . @$VAR['memo']);
$db->Execute($q);
-
-
+
+
# Reciept printing
include_once PATH_MODULES.'invoice/receipt_print.php';
$receipt = new receipt_print;
$receipt->add($rs, number_format($VAR['amount'],2), number_format($update,2));
-
+
# Auto update if billed complete
if($billed)
@@ -1727,27 +1969,27 @@ class invoice
}
$msg = $C_translate->translate('ref_comp','invoice','');
- $C_debug->alert( $msg );
+ $C_debug->alert($msg);
return;
}
- /** REFUND INVOICE
+ /** REFUND INVOICE
*/
function refund($VAR)
{
global $C_translate, $C_debug;
# validate amt
- if( $VAR['amount'] <= 0) {
- $C_debug->alert( "Refund amount to low!" );
+ if($VAR['amount'] <= 0) {
+ $C_debug->alert("Refund amount to low!");
return false;
}
# get the invoice details
$db = &DB();
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'invoice WHERE
- id = ' . $db->qstr( $VAR['id'] ) . ' AND
+ id = ' . $db->qstr($VAR['id']) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$rs = $db->Execute($sql);
if(@$rs->RecordCount() == 0) return false;
@@ -1761,21 +2003,21 @@ class invoice
$update = $billed_amt - $amt;
if($update>0) $billing_status=1; else $billing_status=0;
-
+
# Update the invoice record
echo $sql = 'UPDATE ' . AGILE_DB_PREFIX . 'invoice
SET
- billed_amt = ' . $db->qstr( $update ) . ',
- billing_status = '.$billing_status.',
+ billed_amt = '.$db->qstr($update).',
+ billing_status = '.$billing_status.',
suspend_billing = 1,
- refund_status = 1
+ refund_status = 1
WHERE
- id = ' . $db->qstr( $VAR['id'] ) . ' AND
+ id = ' . $db->qstr($VAR['id']) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$update2 = $db->Execute($sql);
if ($update2 === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','refundInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'refundInvoice', $db->ErrorMsg());
return false;
}
@@ -1793,22 +2035,22 @@ class invoice
$insert = $db->Execute($q);
if ($insert === false) {
global $C_debug;
- $C_debug->error('invoice.inc.php','refundInvoice', $db->ErrorMsg());
+ $C_debug->error(__FILE__,'refundInvoice', $db->ErrorMsg());
return false;
}
# Void:
$this->voidInvoice($VAR, $this);
-
- # Call into the checkout plugin and attempt realtime refund
+
+ # Call into the checkout plugin and attempt realtime refund
$billing = $db->Execute($sql=sqlSelect($db, array('account_billing','checkout'), 'A.*,B.checkout_plugin',
"A.id = ::{$rs->fields['account_billing_id']}:: AND A.checkout_plugin_id=B.id"));
if($billing && $billing->RecordCount() && !empty($billing->fields['checkout_plugin'])) {
$plugin_file = PATH_PLUGINS.'checkout/'. $billing->fields['checkout_plugin'] .'.php';
if(is_file($plugin_file)) {
- include_once ( $plugin_file );
- eval( '$PLG = new plg_chout_' . $billing->fields['checkout_plugin'] . '("'.$billing->fields['checkout_plugin_id'].'");');
- if(is_callable(Array($PLG,"refund"))) $PLG->refund($rs->fields, $billing->fields, $amt);
+ include_once ($plugin_file);
+ eval('$PLG = new plg_chout_' . $billing->fields['checkout_plugin'] . '("'.$billing->fields['checkout_plugin_id'].'");');
+ if(is_callable(array($PLG,"refund"))) $PLG->refund($rs->fields, $billing->fields, $amt);
}
}
@@ -1817,63 +2059,71 @@ class invoice
echo ' ';
return;
}
-
+
$msg = $C_translate->translate('ref_comp','invoice','');
- $C_debug->alert( $msg );
+ $C_debug->alert($msg);
return;
}
# Get translated/hardcoded line item description for PDF invoice
- function getLineItemDesc($sku,$id,$domain=false,$item_name)
- {
- if(!empty($item_name)) return $item_name;
+ # @uses CORE_list;
+ private function getLineItemDesc($sku,$id,$domain=false,$item_name) {
+ if (! empty($item_name))
+ return $item_name;
+
global $C_translate;
- if(!empty($sku) && $sku == 'DOMAIN-PARK' || $sku == 'DOMAIN-TRANSFER' || $sku == 'DOMAIN-REGISTER' || $sku == 'DOMAIN-RENEW') {
- if($sku == 'DOMAIN-REGISTER') $name=$C_translate->translate('register','cart','');
- elseif ($sku == 'DOMAIN-TRANSFER') $name=$C_translate->translate('transfer','cart','');
- elseif ($sku == 'DOMAIN-PARK') $name=$C_translate->translate('park','cart','');
- elseif ($sku == 'DOMAIN-RENEW') $name=$C_translate->translate('renew','cart','');
- if($domain) return "$domain \r\n ( $name )";
- else return $name;
- } else {
- include_once(PATH_CORE.'list.inc.php');
- $C_list=new CORE_list;
- if(empty($this->product_desc["$id"])) {
- $desc = $C_list->translate("product_translate", "name", "product_id", $id, "translate_product");
- $this->product_desc["$id"] = $desc['name'];
+
+ if (! empty($sku) && in_array($sku,array('DOMAIN-PARK','DOMAIN-TRANSFER','DOMAIN-REGISTER','DOMAIN-RENEW'))) {
+ switch ($sku) {
+ case 'DOMAIN-REGISTER': $name = $C_translate->translate('register','cart',''); break;
+ case 'DOMAIN-TRANSFER': $name = $C_translate->translate('transfer','cart',''); break;
+ case 'DOMAIN-PARK': $name = $C_translate->translate('park','cart',''); break;
+ case 'DOMAIN-RENEW': $name = $C_translate->translate('renew','cart',''); break;
}
- if(!empty($this->product_desc["$id"]))
- return $this->product_desc["$id"];
- else
- return $sku;
- }
- return $sku;
+
+ if ($domain)
+ return sprinf("%s\r\n ( %s )",$domain,$name);
+ else
+ return $name;
+
+ } else {
+ include_once(PATH_CORE.'list.inc.php');
+ $C_list = new CORE_list;
+
+ if (empty($this->product_desc[$id])) {
+ $desc = $C_list->translate('product_translate','name','product_id',$id,'translate_product');
+ $this->product_desc[$id] = $desc['name'];
+ }
+
+ if (! empty($this->product_desc[$id]))
+ return $this->product_desc[$id];
+ else
+ return $sku ? $sku : 'Other Item';
+ }
+ }
+
+ // @todo: To be depreciated
+ function delivery_task() {
+ return $this->task_mail_invoices();
}
/**
* Task based function to e-mail or store printable PDF of all unprinted invoices
+ * @todo This seems to be hard limited to do 100 invoices in a run - why? (make it configurable, or remove the limit?)
*/
- function delivery_task()
- {
- # get all unprinted invoices
- $db=&DB();
- $invcfg = $db->Execute(sqlSelect($db,"setup_invoice","*","id=::".DEFAULT_SITE."::"));
- $rs = $db->SelectLimit($sql=sqlSelect($db,Array("invoice","account"),
- "A.id,B.email,B.first_name,B.last_name,B.invoice_delivery,B.invoice_show_itemized",
- "(A.billing_status=0 OR A.billing_status IS NULL) AND (A.print_status=0 OR A.print_status=NULL) and A.account_id=B.id and (B.invoice_delivery is not null AND B.invoice_delivery>0)"),100);
- if($rs && $rs->RecordCount())
- {
- //define('FPDF_FONTPATH', PATH_INCLUDES.'pdf/font/');
- require_once(PATH_INCLUDES.'pdf/fpdi.php');
- require_once(PATH_INCLUDES.'pdf/fpdf_tpl.php');
- require_once(PATH_INCLUDES.'pdf/fpdf.php');
- require_once(PATH_INCLUDES.'pdf/pdf_invoice_'.$invcfg->fields['invoice_pdf_plugin'].'.inc.php');
-
- // Send the e-mail....
- require_once(PATH_INCLUDES."phpmailer/class.phpmailer.php");
+ public function task_mail_invoices() {
+ # Get all unprinted invoices
+ $db = &DB();
+ $rs = $db->SelectLimit(sqlSelect($db,array('invoice','account'),
+ 'A.id,B.email,B.first_name,B.last_name,B.invoice_delivery,B.invoice_show_itemized',
+ '(A.billing_status=0 OR A.billing_status IS NULL) AND (A.print_status=0 OR A.print_status=NULL) and A.account_id=B.id and (B.invoice_delivery IS NOT NULL AND B.invoice_delivery>0)'),100);
+ if ($rs && $rs->RecordCount()) {
+ # Send the e-mail....
+ require_once(PATH_INCLUDES.'phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
- $mail->From = SITE_EMAIL;
+
+ $mail->From = SITE_EMAIL;
$mail->FromName = SITE_NAME;
/*
@@ -1884,319 +2134,326 @@ class invoice
$mail->Mailer = "smtp";
$mail->Debug = true;
*/
-
- while(!$rs->EOF)
- {
- $pdf = new pdf_invoice_overview();
- $pdf->companyName = SITE_NAME;
- $pdf->companyAddress = SITE_ADDRESS;
- $pdf->companyCity = SITE_CITY;
- $pdf->companyState = SITE_STATE;
- $pdf->companyZip = SITE_ZIP;
-
- # load the setup_invoice fields into the pdf class
- $pdf->load_setup($invcfg);
-
- $pagecount = $pdf->setSourceFile($pdf->getTemplate());
- $tplidx = $pdf->ImportPage(1);
-
- $pdf->addPage();
- $pdf->useTemplate($tplidx);
-
- # override the show itemized, based on the customers choice
- if($rs->fields['invoice_show_itemized'] == 0 || $rs->fields['invoice_show_itemized'] == 1)
- $pdf->show_itemized = $rs->fields['invoice_show_itemized'];
-
- $this->pdfInvoiceSummary($rs->fields['id'], $pdf);
- $file = tempnam(PATH_FILES, "pdf_inv_".$rs->fields['id']).".pdf";
- $pdf->Output($file,'F');
- $pdf->closeParsers();
-
- if($rs->fields['invoice_delivery'] == 1) {
- $mail->AddAddress($rs->fields['email'], $rs->fields['first_name']. ' ' . $rs->fields['last_name']);
- $mail->Subject = "Printable Invoice No. ". $rs->fields['id'];
- $mail->Body = "Please find the printable version of invoice number {$rs->fields['id']} attached.\r\n\r\nThank you,\r\n".SITE_NAME;
- $mail->AddAttachment($file, "INVOICE_{$rs->fields['id']}.pdf");
-
- if($mail->Send()) {
- $fields=Array('print_status'=>1);
- $db->Execute(sqlUpdate($db,"invoice",$fields,"id=".$rs->fields['id']));
- } else {
- echo "Unable to email invoice # {$rs->fields['id']} to {$rs->fields['email']} ";
- }
-
- $mail->ClearAddresses();
- $mail->ClearAttachments();
- } else if($rs->fields['invoice_delivery'] == 2) {
- if(copy($file,AGILE_PDF_INVOICE_PATH."invoice_".$rs->fields['id'].".pdf")) {
- $fields=Array('print_status'=>1);
- $db->Execute(sqlUpdate($db,"invoice",$fields,"id=".$rs->fields['id']));
- }
+ while (! $rs->EOF) {
+ if (! $pdf = $this->initInvoicePDF(array('id'=>$rs->fields['id'])))
+ continue;
+
+ $this->pdfInvoiceSummary($rs->fields['id'],$pdf);
+
+ switch ($rs->fields['invoice_delivery']) {
+ # Email Invoice
+ case 1:
+ $file = $pdf->Output(null,'S');
+
+ $mail->AddAddress($rs->fields['email'], sprintf('%s %s',$rs->fields['first_name'],$rs->fields['last_name']));
+ $mail->Subject = sprintf('%s %s: %s',SITE_NAME,_('Invoice'),$rs->fields['id']);
+ $mail->Body = sprintf("Please find the printable version of invoice number %s attached.\r\n\r\nThank you,\r\n%s",$rs->fields['id'],SITE_NAME);
+ $mail->AddStringAttachment($file,sprintf('%s.pdf',$this->getInvoiceID()),'base64','application/pdf');
+
+ if ($mail->Send())
+ $db->Execute(sqlUpdate($db,'invoice',array('print_status'=>1),array('id'=>$rs->fields['id'])));
+ else
+ printf('Unable to email invoice # %s to %s ',$rs->fields['id'],$rs->fields['email']);
+
+ $mail->ClearAddresses();
+ $mail->ClearAttachments();
+
+ break;
+
+ # Print Invoice
+ case 2:
+ $file = tempnam(PATH_FILES,sprintf('pdf_inv_%s.pdf',$this->getInvoiceID()));
+ $pdf->Output($file,'F');
+
+ if (copy($file,sprintf('%sinvoice_%s.pdf',AGILE_PDF_INVOICE_PATH,$this->getInvoiceID())))
+ $db->Execute(sqlUpdate($db,'invoice',array('print_status'=>1),array('id'=>$rs->fields['id'])));
+
+ unlink($file);
+ break;
+
+ default:
+ printf('Unknown invoice_delivery: %s for %s ',$rs->fields['invoice_delivery'],$rs->fields['id']);
}
-
- // delete tmp file and clean up vars used
- unlink($file);
- unset($pdf->itemsSummary);
- unset($pdf); unset($tplidx); unset($pagecount);
-
- $rs->MoveNext();
- }
- }
+
+ $rs->MoveNext();
+ }
+ }
}
-
-
- /** Display a PDF invoice
- */
- function pdf($VAR)
- {
+
+ /**
+ * Initialise an invoice
+ *
+ * This function is responsible for getting all the information required to render an invoice.
+ */
+ private function initInvoicePrint($VAR) {
# Check invoice
- if(empty($VAR['id'])) {
+ if (! isset($VAR['id'])) {
echo 'No Invoice Specified.';
+
return false;
}
# Check admin authentication:
global $C_auth;
+ $db = &DB();
+
if ($C_auth->auth_method_by_name('invoice','view') == false) {
# Validate on account level
- $db = &DB();
- $rs = $db->Execute(sqlSelect($db,"invoice","account_id", "id = ::{$VAR['id']}::"));
- if ($rs->fields['account_id'] != SESS_ACCOUNT) {
- // todo: redirect to login page if not logged
+ $rs = $db->Execute(sqlSelect($db,'invoice','account_id',array('id'=>$VAR['id'])));
+
+ # @todo redirect to login page if not logged
+ if ($rs->fields['account_id'] != SESS_ACCOUNT)
return false;
- }
}
- $db =& DB();
- $invcfg = $db->Execute(sqlSelect($db,"setup_invoice","*","id=::".DEFAULT_SITE."::"));
-
- if (!defined('FPDF_FONTPATH'))
- define('FPDF_FONTPATH', PATH_INCLUDES.'pdf/font/');
- require_once(PATH_INCLUDES.'pdf/fpdi.php');
- require_once(PATH_INCLUDES.'pdf/fpdf_tpl.php');
- require_once(PATH_INCLUDES.'pdf/fpdf.php');
- require_once(PATH_INCLUDES.'pdf/pdf_invoice_'.$invcfg->fields['invoice_pdf_plugin'].'.inc.php');
-
- ob_start();
-
- $pdf = new pdf_invoice_overview();
- $pdf->companyName = SITE_NAME;
- $pdf->companyAddress = SITE_ADDRESS;
- $pdf->companyCity = SITE_CITY;
- $pdf->companyState = SITE_STATE;
- $pdf->companyZip = SITE_ZIP;
-
- # load the setup_invoice
- $pdf->load_setup($invcfg);
-
- $pagecount = $pdf->setSourceFile($pdf->getTemplate());
- $tplidx = $pdf->ImportPage(1);
+ $invoice = array();
+
+ #@todo this should be in setup_invoice
+ $invoice['site']['TAXID'] = SITE_TAXID;
+ $invoice['site']['NAME'] = SITE_NAME;
+ $invoice['site']['ADDRESS'] = SITE_ADDRESS;
+ $invoice['site']['CITY'] = SITE_CITY;
+ $invoice['site']['STATE'] = SITE_STATE;
+ $invoice['site']['ZIP'] = SITE_ZIP;
+ $invoice['site']['FAX'] = SITE_FAX;
+ $invoice['site']['PHONE'] = SITE_PHONE;
+ $invoice['site']['EMAIL'] = SITE_EMAIL;
+ $invoice['site']['URL'] = URL;
+
+ # Invoice Configuration
+ $rs = $db->Execute(sqlSelect($db,'setup_invoice','*',''));
+ $invoice['invcfg'] = $rs->fields;
+
+ # Invoice details
+ $rs = $db->Execute($a=sqlSelect($db,array('invoice','currency'),'A.*,B.symbol',sprintf('A.id=%s AND B.id=A.billed_currency_id',$VAR['id'])));
+ $invoice['invoice'] = $rs->fields;
+
+ # Account detail:
+ $rs = $db->Execute($q = sqlSelect($db,'account','*',array('id'=>$invoice['invoice']['account_id'])));
+ $invoice['account'] = $rs->fields;
+
+ # Invoice Item details
+ $invoice['invoiceitems'] = array();
+ $rs = $db->Execute($b=sqlSelect($db,'invoice_item','*',array('invoice_id'=>$VAR['id'])));
+ while (! $rs->EOF) {
+ array_push($invoice['invoiceitems'],$rs->fields);
+ $rs->moveNext();
+ }
+
+ # Get previous invoices
+ $invoice['previousinvoices'] = array();
+ $rs = $db->Execute($q=sqlSelect($db,'invoice','*',sprintf('account_id=%s AND (billed_amt < total_amt OR billed_amt IS NULL) AND date_orig < %s',
+ $invoice['invoice']['account_id'],$invoice['invoice']['date_orig'])));
+
+ while (! $rs->EOF) {
+ array_push($invoice['previousinvoices'],$rs->fields);
+ $rs->moveNext();
+ }
+
+ # If we get here, all is OK.
+ return $invoice;
+ }
+
+ /**
+ * Initialise a PDF invoice
+ *
+ * This function is resonsible for setting up a PDF invoice
+ */
+ private function initInvoicePDF($VAR) {
+ # Get our invoice details
+ if (! $this->print = $this->initInvoicePrint($VAR))
+ return false;
+
+ #@todo since the view template dynamic finds available plugins, this should also find the plugin (incase the prefix/dir is moved).
+ require_once(sprintf('%sinvoice/PDF/pdf_invoice_%s.inc.php',PATH_MODULES,$this->print['invcfg']['invoice_pdf_plugin']));
+
+ $pdf = new pdf_invoice_overview($this);
+
+ #@todo This should be deprecated
+ $null = false;
+ $pdf->load_setup($null);
+
+ if ($pdf->getTemplate()) {
+ $pagecount = $pdf->setSourceFile($pdf->getTemplate());
+ $tplidx = $pdf->ImportPage(1);
+ }
+
$pdf->addPage();
- $pdf->useTemplate($tplidx);
- $this->pdfInvoiceSummary($VAR['id'], $pdf);
- $pdf->Output('invoice.pdf','D');
- $pdf->closeParsers();
-
- ob_end_flush();
+
+ # If we are using FPDI
+ if (isset($tplidx))
+ $pdf->useTemplate($tplidx);
+
+ # If we get here, all is OK.
+ return $pdf;
+ }
+
+ /**
+ * Display a PDF invoice in the browser for download.
+ */
+ public function pdf($VAR) {
+ if (! $pdf = $this->initInvoicePDF($VAR))
+ return false;
+
+ $this->pdfInvoiceSummary($VAR['id'],$pdf);
+ $pdf->Output(sprintf('%s.pdf',$this->getInvoiceID()),'I');
}
/** Export multiple invoices */
- function pdfExport(&$rs)
- {
+ function pdfExport(&$rs)
+ {
$db =& DB();
$invcfg = $db->Execute(sqlSelect($db,"setup_invoice","*",""));
-
- define('FPDF_FONTPATH', PATH_INCLUDES.'pdf/font/');
- require_once(PATH_INCLUDES.'pdf/fpdi.php');
- require_once(PATH_INCLUDES.'pdf/fpdf_tpl.php');
- require_once(PATH_INCLUDES.'pdf/fpdf.php');
- require_once(PATH_INCLUDES.'pdf/pdf_invoice_'.$invcfg->fields['invoice_pdf_plugin'].'.inc.php');
-
- ob_start();
- $pdf = new pdf_invoice_overview();
+
+ ob_start();
+ $pdf = new pdf_invoice_overview();
$pdf->companyName = SITE_NAME;
$pdf->companyAddress = SITE_ADDRESS;
$pdf->companyCity = SITE_CITY;
$pdf->companyState = SITE_STATE;
- $pdf->companyZip = SITE_ZIP;
- $pdf->load_setup($invcfg);
+ $pdf->companyZip = SITE_ZIP;
+ $pdf->load_setup($invcfg);
+ if ($pdf->getTemplate())
$pagecount = $pdf->setSourceFile($pdf->getTemplate());
- $tplidx = $pdf->ImportPage(1);
- while(!$rs->EOF) {
+ $tplidx = $pdf->ImportPage(1);
+ while(!$rs->EOF) {
$pdf->addPage();
- $pdf->useTemplate($tplidx);
- $this->pdfInvoiceSummary($rs->fields['id'], $pdf);
+ $pdf->useTemplate($tplidx);
+ $this->pdfInvoiceSummary($rs->fields['id'], $pdf);
$rs->MoveNext();
unset($pdf->itemsSummary);
- }
+ }
$pdf->Output();
- $pdf->closeParsers();
- ob_end_flush();
+ ob_end_flush();
}
-
-
- function pdfInvoiceSummary($id, &$pdf)
- {
+ /**
+ * Render an invoice with the summary page
+ * @todo Draw discounts
+ * @todo Draw tax details
+ */
+ private function pdfInvoiceSummary($id,$pdf) {
# Invoice details:
- $db = &DB();
- $invoice = $db->Execute( $sql = sqlSelect($db, array("invoice", "currency"), "A.*, B.symbol", "A.id = ::$id:: AND B.id = A.billed_currency_id"));
- $pdf->setInvoiceFields($invoice->fields);
- $pdf->setDueAmt($invoice->fields['total_amt'] - $invoice->fields['billed_amt']);
- $pdf->setCurrency($invoice->fields['symbol']);
- $pdf->setDateRange( mktime(0,0,0,date('m',$invoice->fields['due_date'])-1, date('d',$invoice->fields['due_date']), date('Y',$invoice->fields['due_date'])), $invoice->fields['due_date']);
- $pdf->drawInvoiceNo();
- $pdf->drawInvoiceDueDate();
- $pdf->drawInvoiceTotalAmt();
- $pdf->drawInvoiceDueAmt();
- $pdf->drawInvoicePaidAmt();
- $pdf->drawInvoiceDiscountAmt();
- $pdf->drawInvoiceTaxAmt();
- $pdf->drawInvoiceShippingAmt();
- $pdf->drawInvoiceRange();
- if($invoice->fields['billing_status'] !=1 && $invoice->fields['suspend_billing'] != 1 && $invoice->fields['due_date'] <= time())
- $pdf->drawInvoiceDueNotice();
- elseif($invoice->fields['billing_status'] == 1)
- $pdf->drawInvoicePaidNotice();
-
- # Account details:
- $account = $db->Execute("SELECT * FROM ".AGILE_DB_PREFIX."account WHERE id = ".$db->qstr($invoice->fields['account_id'])." AND site_id = ".$db->qstr(DEFAULT_SITE));
- $pdf->setAccountFields($account->fields);
- $pdf->drawAccountId();
- $pdf->drawAccountUsername();
- $pdf->drawAccountName();
- $pdf->drawAccountMailing();
-
- # Company details:
- $pdf->drawCompanyAddress();
- $pdf->drawCompanyLogo();
-
- ## Get the summary items
- $items = & $db->Execute("select sku, item_type, product_name, product_id, sum(quantity) as quantity, (sum(total_amt)) as amount, price_setup, price_base from ".AGILE_DB_PREFIX."invoice_item where invoice_id=".$db->qstr($id)." group by sku, item_type");
- $i = 0;
- if($items && $items->RecordCount()) {
- while (!$items->EOF) {
- $items_arr[$i] = $items->fields;
- $desc = $this->getLineItemDesc($items->fields['sku'], $items->fields['product_id'], false, $items->fields['product_name']);
- $items_arr[$i]['name'] = $desc;
- $i++;
- if ($items->fields['price_setup']) {
- $items_arr[$i]['name'] = $desc." Set-up Charge";
- $items_arr[$i]['amount'] = $items->fields['price_setup'];
- $i++;
- }
- $items->MoveNext();
- }
- }
- if ($invoice->fields['discount_amt']) {
- $items_arr[$i]['name'] = 'Discount';
- $items_arr[$i]['amount'] = -($invoice->fields['discount_amt']);
- $i++;
- }
- if ($invoice->fields['tax_amt']) {
- $trs = $db->Execute($sql=sqlSelect($db, Array('invoice_item_tax','tax'),"A.amount,B.description","A.tax_id=B.id AND A.invoice_id=::$id::"));
- if($trs && $trs->RecordCount()) {
- unset($taxes);
- while(!$trs->EOF) {
- $taxes["{$trs->fields['description']}"] += $trs->fields["amount"];
- $trs->MoveNext();
- }
- foreach($taxes as $txds=>$txamt) {
- $items_arr[$i]['name'] = $txds;
- $items_arr[$i]['amount'] = $txamt;
- $i++;
- }
- }
- }
- $pdf->drawSummaryLineItems($items_arr);
- unset($items_arr);
+ $db = &DB();
+
+ # Draw Invoice Basics
+ $pdf->drawCompanyLogo();
+ $pdf->drawCompanyAddress($this);
+
+ $pdf->drawInvoiceHeader($this);
+ $pdf->drawNews($this->print['invcfg']['news']);
+ $pdf->drawRemittenceStub($this);
+ $pdf->drawPaymentMethods($this);
+
+ if ($this->print['invoice']['billing_status'] !=1 && $this->print['invoice']['suspend_billing'] != 1 && $this->print['invoice']['due_date'] <= time())
+ $pdf->drawInvoiceDueNotice();
+ elseif($this->print['invoice']['billing_status'] == 1)
+ $pdf->drawInvoicePaidNotice();
+
+ if ($this->getPreviousBalance())
+ $pdf->drawSummaryInvoicesDue($this->print['previousinvoices']);
+
+ $pdf->drawSummaryLineItems($this);
unset($pdf->itemsSummary);
-
- ## BEGIN loop for enumerating information in multiple ways on the invoice
+
+ # BEGIN loop for enumerating information in multiple ways on the invoice
$iteration = 0;
- while($pdf->drawLineItems_pre($iteration)) {
- ## Get the line items:
- $items = & $db->Execute( sqlSelect($db, "invoice_item", "*", "invoice_id = ::$id::") );
- if ($items && $items->RecordCount()) {
- while ( !$items->EOF ) {
- #$items_arr[] = $items->fields;
- // get the date range if set
- if(!empty($items->fields['date_start']) && !empty($items->fields['date_stop'])) {
+ while ($pdf->drawLineItems_pre($iteration)) {
+ # Get the line items:
+ $items = $db->Execute(sqlSelect($db,'invoice_item','*',array('invoice_id'=>$this->getInvoiceNum())));
+ if ($items && $items->RecordCount()) {
+ while (! $items->EOF) {
+ # Get the date range if set
+ if (! empty($items->fields['date_start']) && ! empty($items->fields['date_stop'])) {
global $C_translate;
- $C_translate->value('invoice','start', date(UNIX_DATE_FORMAT,$items->fields['date_start']));
- $C_translate->value('invoice','stop', date(UNIX_DATE_FORMAT,$items->fields['date_stop']));
- #$smart_items[$ii]['range'] = $C_translate->translate('recur_date_range','invoice','');
+ $C_translate->value('invoice','start',date(UNIX_DATE_FORMAT,$items->fields['date_start']));
+ $C_translate->value('invoice','stop',date(UNIX_DATE_FORMAT,$items->fields['date_stop']));
}
-
+
$cost = $items->fields['price_base'];
$total = $cost * $items->fields['quantity'];
- $desc = $this->getLineItemDesc($items->fields['sku'],$items->fields['product_id'], strtolower($items->fields['domain_name'].'.'.$items->fields['domain_tld']), $items->fields['product_name']);
+ $desc = $this->getLineItemDesc($items->fields['sku'],$items->fields['product_id'],strtolower($items->fields['domain_name'].'.'.$items->fields['domain_tld']),$items->fields['product_name']);
$line = array(
- "name" => $desc,
- 'amount' => $cost,
- 'sku'=>$items->fields['sku'],
- 'qty'=>$items->fields['quantity'],
- 'cost'=>$cost,
- 'attr'=>$items->fields['product_attr'],
- 'price_type'=>$items->fields['price_type'],
- 'price_base'=>$items->fields['price_base'],
+ 'name' => $desc,
+ 'domain' => $items->fields['domain_name'],
+ 'amount' => $cost,
+ 'sku'=>$items->fields['sku'],
+ 'qty'=>$items->fields['quantity'],
+ 'cost'=>$cost,
+ 'attr'=>$items->fields['product_attr'],
+ 'price_type'=>$items->fields['price_type'],
+ 'price_base'=>$items->fields['price_base'],
'item_type'=>$items->fields['item_type'],
+ 'daterange'=>sprintf('%s - %s',date(UNIX_DATE_FORMAT,$items->fields['date_start']),date(UNIX_DATE_FORMAT,$items->fields['date_stop'])),
'total_amt'=>$items->fields['total_amt']
- );
- $pdf->drawLineItems($db, $line);
+ );
+
+ $pdf->drawLineItems($db,$line,$this->getInvoiceNum());
+
if ($items->fields['price_setup']) {
- $desc .= " Set-up Charge";
+ $desc .= ' Set-up Charge';
$total = $items->fields['price_setup'];
- $line = array("name" => $desc, 'amount' => $total, 'qty'=>'1', 'sku'=>$items->fields['sku'], 'cost'=>$total, 'price_base'=>$total, 'price_type'=>999);
- $pdf->drawLineItems($db, $line);
+ $line = array('name'=>$desc,'amount'=>$total,'qty'=>'1','sku'=>$items->fields['sku'],'cost'=>$total,'price_base'=>$total,'price_type'=>999);
+ $pdf->drawLineItems($db,$line,$this->getInvoiceNum());
}
+
$items->MoveNext();
}
- }
- if ($invoice->fields['discount_amt']) {
+ }
+
+ if ($this->print['invoice']['discount_amt']) {
$desc = 'Discount';
- $total = -($invoice->fields['discount_amt']);
- $line = array("name" => $desc, 'amount' => $total, 'qty'=>'1', 'cost'=>$total, 'price_base'=>$total, 'price_type'=>999);
- $pdf->drawLineItems($db, $line);
+ $total = -($this->print['invoice']['discount_amt']);
+ $line = array('name'=>$desc,'amount'=>$total,'qty'=>'1','cost'=>$total,'price_base'=>$total,'price_type'=>999);
+ $pdf->drawLineItems($db,$line,$this->getInvoiceNum());
}
- if ($invoice->fields['tax_amt']) {
- $trs = $db->Execute($sql=sqlSelect($db, Array('invoice_item_tax','tax'),"A.amount,B.description","A.tax_id=B.id AND A.invoice_id=::$id::"));
- if($trs && $trs->RecordCount()) {
- unset($taxes);
- while(!$trs->EOF) {
- $taxes["{$trs->fields['description']}"] += $trs->fields["amount"];
- $trs->MoveNext();
- }
- foreach($taxes as $txds=>$txamt) {
- $line = array("name" => $txds, 'amount' => $txamt, 'qty'=>'1', 'cost'=>$txamt, 'price_base'=>$txamt, 'price_type'=>999);
- $pdf->drawLineItems($db, $line);
+
+ if ($this->print['invoice']['tax_amt']) {
+ $trs = $db->Execute(sqlSelect($db,array('invoice_item_tax','tax'),'A.amount,B.description',sprintf('A.tax_id=B.id AND A.invoice_id=%s',$this->getInvoiceNum())));
+ if ($trs && $trs->RecordCount()) {
+ $taxes = array();
+
+ while (! $trs->EOF) {
+ if (! isset($taxes[$trs->fields['description']]))
+ $taxes[$trs->fields['description']] = $trs->fields['amount'];
+ else
+ $taxes[$trs->fields['description']] += $trs->fields['amount'];
+
+ $trs->MoveNext();
}
- }
+
+ foreach ($taxes as $txds=>$txamt) {
+ $line = array('name'=>$txds,'amount'=>$txamt,'total_amt'=>$txamt,'price_type'=>999);
+ $pdf->drawLineItems($db,$line,$this->getInvoiceNum());
+ }
+ }
}
+
# Increment the iteration
++$iteration;
}
+
# Custom functions:
- $pdf->drawCustom();
- unset($db);
+ $pdf->drawCustom();
+ unset($db);
}
- /** RESEND DUE NOTICE
+ /** RESEND DUE NOTICE
*/
function resend($VAR)
{
global $C_debug;
-
+
# User invoice creation confirmation
include_once(PATH_MODULES.'email_template/email_template.inc.php');
$mail = new email_template;
$mail->send('invoice_resend', $VAR['account_id'], $VAR['id'], '', '');
-
+
# Alert
$C_debug->alert('Sent payment due notice to user');
-
+
# Update invoice
$db = &DB();
$q = "SELECT notice_count FROM ".AGILE_DB_PREFIX."invoice WHERE
@@ -2211,414 +2468,510 @@ class invoice
$rs = $db->Execute($q);
}
-
+
/**
- * Generate all invoices for recurring services/charges/domains
+ * Generate all invoices for recurring services/charges/domains
*/
- function generate() {
-
- // check if charge module installed
+ public function generate() {
+ # Check if charge module installed
global $C_list;
- $charge_installed = $C_list->is_installed('charge');
-
+ $isChargeInstalled = $C_list->is_installed('charge');
+
// get services to be billed grouped by account and date
- if(MAX_INV_GEN_PERIOD <= 0) $max_date = time()+86400; else $max_date = time()+(MAX_INV_GEN_PERIOD*86400);
- $p=AGILE_DB_PREFIX; $s=DEFAULT_SITE;
- $ids=false;
- $account=false;
- $date=false;
- $invoice=false;
- $sql = "SELECT DISTINCT service.id as serviceId, account.id as accountId, invoice.id as invoiceId, from_unixtime(service.date_next_invoice,'%Y-%m-%d') as dayGroup
- FROM {$p}service as service
+ if (! defined('MAX_INV_GEN_PERIOD') || MAX_INV_GEN_PERIOD <= 0)
+ $max_date = time()+86400;
+ else
+ $max_date = time()+(MAX_INV_GEN_PERIOD*86400);
+
+ #$p=AGILE_DB_PREFIX; $s=DEFAULT_SITE;
+/*
+ $sql = "SELECT DISTINCT service.id as serviceId, account.id as accountId, invoice.id as invoiceId, from_unixtime(service.date_next_invoice,'%Y-%m-%d') as dayGroup
+ FROM {$p}service as service
JOIN {$p}account as account ON ( service.account_id=account.id and account.site_id={$s} )
LEFT JOIN {$p}invoice as invoice ON ( service.invoice_id=invoice.id and invoice.site_id={$s} )
- WHERE service.site_id={$s}
- AND service.active = 1
- AND ( service.suspend_billing IS NULL OR service.suspend_billing = 0 )
+ WHERE service.site_id={$s}
+ AND service.active = 1
+ AND ( service.suspend_billing IS NULL OR service.suspend_billing = 0 )
AND ( service.date_next_invoice > 0 AND service.date_next_invoice IS NOT NULL )
- AND
+ AND
((
- ( account.invoice_advance_gen!='' OR account.invoice_advance_gen is not null ) AND service.date_next_invoice <= (UNIX_TIMESTAMP(CURDATE())+(account.invoice_advance_gen*86400))
- ) OR (
- ( account.invoice_advance_gen='' OR account.invoice_advance_gen is null ) AND service.date_next_invoice <= {$max_date}
+ (account.invoice_advance_gen!='' OR account.invoice_advance_gen is not null) AND service.date_next_invoice <= (UNIX_TIMESTAMP(CURDATE())+(account.invoice_advance_gen*86400))
+ ) OR (
+ (account.invoice_advance_gen='' OR account.invoice_advance_gen is null) AND service.date_next_invoice <= {$max_date}
))
- ORDER BY accountId, dayGroup, serviceId";
+ ORDER BY accountId, dayGroup, serviceId";
+*/
$db=&DB();
- #$db->debug=true;
- $rs=$db->Execute($sql);
- if($rs === false) {global $C_debug; $C_debug->error('invoice.inc.php','generate()', $sql . " \r\n\r\n " . @$db->ErrorMsg()); }
- if($rs && $rs->RecordCount()) {
- while(!$rs->EOF) {
- if( $ids && ($rs->fields['accountId'] != $account ) || ($rs->fields['dayGroup'] != $date) ) {
- $this->generateInvoices($ids, $account, $invoice, $charge_installed);
- $ids=false;
+ $rs = $db->Execute($sql = $this->sql_invoice_soon());
+ if (! $rs) {
+ global $C_debug;
+
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+
+ } elseif($rs->RecordCount()) {
+ $ids = '';
+ $account = '';
+ $date = '';
+ $invoice = '';
+
+ while (! $rs->EOF) {
+ if ($ids && (($rs->fields['aid'] != $account) || ($rs->fields['invoice_date'] != $date))) {
+ $this->generateInvoices($ids,$account,$invoice,$isChargeInstalled);
+ $ids = '';
}
-
- // set the current account and date
- $account=$rs->fields['accountId'];
- $invoice=$rs->fields['invoiceId'];
- $date=$rs->fields['dayGroup'];
-
- // add to id list
- if($ids) $ids.=",";
- $ids.=$rs->fields['serviceId'];
+
+ # Set the current account and date
+ $account = $rs->fields['aid'];
+ $invoice = $rs->fields['iid'];
+ $date = $rs->fields['invoice_date'];
+
+ # Add to id list
+ if ($ids)
+ $ids .= ','.$rs->fields['sid'];
+ else
+ $ids = $rs->fields['sid'];
+
$rs->MoveNext();
}
- if($ids) $this->generateInvoices($ids, $account, $invoice, $charge_installed);
+
+ if ($ids)
+ $this->generateInvoices($ids,$account,$invoice,$isChargeInstalled);
}
-
- // Generate invoices for any domains expiring in X days.
- if($C_list->is_installed('host_tld')) $this->generateDomains();
-
+
+ // Generate invoices for any domains expiring in X days.
+ if ($C_list->is_installed('host_tld'))
+ $this->generateDomains();
+
return true;
}
-
-
- function generateInvoices($ids, $account_id, $invoice_id, $charge_installed=false) {
- if(empty($ids)) return false;
-
- # load required elements
- include_once(PATH_MODULES . 'service/service.inc.php');
- include_once(PATH_MODULES . 'discount/discount.inc.php');
- include_once(PATH_MODULES . 'tax/tax.inc.php');
+ public function generateinvoice_account($VAR) {
+ # Check if charge module installed
+ global $C_list;
+
+ $charge_installed = $C_list->is_installed('charge');
+
+ $db = &DB();
+ $rs = $db->Execute($q = $this->sql_invoice_soon(null,0,$VAR['account_id']));
+
+ if (! $rs) {
+ global $C_debug;
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+
+ return;
+ }
+
+ # Set the invoice and date
+ $invoice = $rs->fields['iid'];
+ $date = $rs->fields['invoice_date'];
+ $ids = '';
+
+ while (! $rs->EOF) {
+ if ($ids && ($rs->fields['invoice_date'] != $date)) {
+ $this->generateInvoices($ids,$VAR['account_id'],$invoice,$charge_installed);
+ $ids = '';
+ }
+
+ # Add to id list
+ if ($ids)
+ $ids .= ',';
+
+ $ids .= $rs->fields['sid'];
+ $rs->MoveNext();
+ }
+
+ if ($ids)
+ $this->generateInvoices($ids,$VAR['account_id'],$invoice,$charge_installed);
+
+ if (isset($VAR['_page_next']))
+ define('REDIRECT_PAGE','?_page='.$VAR['_page_next']);
+ }
+
+ /**
+ * Generate an Invoice
+ */
+ private function generateInvoices($ids,$account_id,$invoice_id,$charge_installed=false) {
+ if (empty($ids))
+ return false;
+
+ # Load required elements
+ include_once(PATH_MODULES.'service/service.inc.php');
+ $serviceObj = new service;
+
+ include_once(PATH_MODULES.'discount/discount.inc.php');
+ $discountObj = new discount;
+
+ include_once(PATH_MODULES.'tax/tax.inc.php');
$taxObj = new tax;
- $serviceObj = new service;
-
- # start a transaction
- $db=&DB();
- #$db->debug=true;
- if(AGILE_DB_TYPE == 'mysqlt') {
+
+ # Start a transaction
+ $db = &DB();
+ if (AGILE_DB_TYPE == 'mysqlt') {
$db->StartTrans();
- if(!$db->hasTransactions) {
+
+ if (! $db->hasTransactions) {
global $C_debug;
- $msg= "Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver";
+
+ $msg = "Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver";
$C_debug->alert($msg);
- $C_debug->error('invoice.inc.php','generateInvoices()', "Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver");
- return false;
+ $C_debug->error(__FILE__,__METHOD__,$msg);
+
+ return false;
}
}
-
- # generate an invoice id
- $invoice = sqlGenID($db, 'invoice');
-
- # check for any discounts for the parent invoice or account_id
+
+ # Generate an invoice id
+ $invoice = sqlGenID($db,'invoice');
+
+ # Check for any discounts for the parent invoice or account_id
# applied at checkout and should continue to be applied if recurring type discount
- $discountObj = new discount;
- $discountObj->available_discounts($account_id, 1, $invoice_id);
-
- # beginning totals
- $sub_total=0;
- $taxable_amount=0;
- $tax_amt=0;
- $discount_amt=0;
-
- # get the full account and service and invoice details
+ $discountObj->available_discounts($account_id,1,$invoice_id);
+
+ # Beginning totals
+ $sub_total = 0;
+ $total = 0;
+ $taxable_amount = 0;
+ $tax_amt = 0;
+ $discount_amt = 0;
+
+ # Get the full account and service and invoice details
$p=AGILE_DB_PREFIX; $s=DEFAULT_SITE;
- $sql = "SELECT DISTINCT
- service.id, service.parent_id, service.invoice_id, service.invoice_item_id, service.account_id, service.account_billing_id, service.product_id,
- service.sku, service.active, service.bind, service.type, service.price, service.price_type, service.taxable, service.date_last_invoice, service.date_next_invoice,
- service.recur_type, service.recur_schedule, service.recur_weekday, service.recur_week, service.domain_name,
- service.domain_tld, service.domain_type, service.domain_term, service.prod_attr, service.prod_attr_cart,
- account.currency_id, account.first_name, account.last_name, account.country_id, account.state, account.invoice_grace, account.invoice_advance_gen, account.affiliate_id as account_affiliate_id,
- invoice.affiliate_id, invoice.campaign_id, invoice.reseller_id, invoice.checkout_plugin_id, invoice.checkout_plugin_data, invoice.billed_currency_id, invoice.actual_billed_currency_id
- FROM {$p}service as service
- JOIN {$p}account as account ON ( service.account_id=account.id and account.site_id={$s} )
- LEFT JOIN {$p}invoice as invoice ON ( service.invoice_id=invoice.id and invoice.site_id={$s} )
- WHERE service.id in ({$ids})";
- $service=$db->Execute($sql);
- if($service === false) {global $C_debug; $C_debug->error('invoice.inc.php','generateInvoices()1', $sql . " \r\n\r\n " . @$db->ErrorMsg()); $db->FailTrans(); return false; }
- if($service && $service->RecordCount()) {
- while(!$service->EOF) {
-
- if(empty($service->fields['billed_currency_id'])) $service->fields['billed_currency_id'] = DEFAULT_CURRENCY;
- if(empty($service->fields['actual_billed_currency_id'])) $service->fields['actual_billed_currency_id'] = $service->fields['billed_currency_id'];
-
- $this->account_id=$service->fields['account_id'];
- $this->parent_id=$service->fields['invoice_id'];
- $this->account_billing_id=$service->fields['account_billing_id'];
- if(!empty($service->fields['account_affiliate_id']))
- $this->affiliate_id=$service->fields['account_affiliate_id'];
- else
- $this->affiliate_id=$service->fields['affiliate_id'];
- $this->campaign_id=$service->fields['campaign_id'];
- $this->reseller_id=$service->fields['reseller_id'];
- $this->checkout_plugin_id=$service->fields['checkout_plugin_id'];
- $this->checkout_plugin_data=$service->fields['checkout_plugin_data'];
- $this->billed_currency_id=$service->fields['billed_currency_id'];
- $this->actual_billed_currency_id=$service->fields['actual_billed_currency_id'];
- $this->invoice_grace=$service->fields['invoice_grace'];
-
- $item_tax_amt=0;
- $item_total_amt=0;
- $item_discount_amt=0;
-
- # gen item_id
- $item = sqlGenID($db, "invoice_item");
-
+ $sql = "SELECT DISTINCT
+ service.id, service.parent_id, service.invoice_id, service.invoice_item_id, service.account_id, service.account_billing_id, service.product_id,
+ service.sku, service.active, service.bind, service.type, service.price, service.price_type, service.taxable, service.date_last_invoice, service.date_next_invoice,
+ service.recur_type, service.recur_schedule, service.recur_weekday, service.recur_week, service.domain_name,
+ service.domain_tld, service.domain_type, service.domain_term, service.prod_attr, service.prod_attr_cart,
+ account.currency_id, account.first_name, account.last_name, account.country_id, account.state, account.invoice_grace, account.invoice_advance_gen, account.affiliate_id as account_affiliate_id,
+ invoice.affiliate_id, invoice.campaign_id, invoice.reseller_id, invoice.checkout_plugin_id, invoice.checkout_plugin_data, invoice.billed_currency_id, invoice.actual_billed_currency_id
+ FROM {$p}service as service
+ JOIN {$p}account as account ON (service.account_id=account.id AND account.site_id={$s})
+ LEFT JOIN {$p}invoice as invoice ON (service.invoice_id=invoice.id AND invoice.site_id={$s})
+ WHERE service.id in ({$ids})";
+
+ $service = $db->Execute($sql);
+ if ($service === false) {
+ global $C_debug;
+
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+ $db->FailTrans();
+
+ return false;
+ }
+
+ if ($service && $service->RecordCount()) {
+ while (! $service->EOF) {
+ if (empty($service->fields['billed_currency_id']))
+ $service->fields['billed_currency_id'] = DEFAULT_CURRENCY;
+ if (empty($service->fields['actual_billed_currency_id']))
+ $service->fields['actual_billed_currency_id'] = $service->fields['billed_currency_id'];
+
+ $this->account_id = $service->fields['account_id'];
+ $this->parent_id = $service->fields['invoice_id'];
+ $this->account_billing_id = $service->fields['account_billing_id'];
+
+ if (! empty($service->fields['account_affiliate_id']))
+ $this->affiliate_id = $service->fields['account_affiliate_id'];
+ else
+ $this->affiliate_id = $service->fields['affiliate_id'];
+
+ $this->campaign_id = $service->fields['campaign_id'];
+ $this->reseller_id = $service->fields['reseller_id'];
+ $this->checkout_plugin_id = $service->fields['checkout_plugin_id'];
+ $this->checkout_plugin_data = $service->fields['checkout_plugin_data'];
+ $this->billed_currency_id = $service->fields['billed_currency_id'];
+ $this->actual_billed_currency_id = $service->fields['actual_billed_currency_id'];
+ $this->invoice_grace = $service->fields['invoice_grace'];
+
+ $item_tax_amt = 0;
+ $item_total_amt = 0;
+ $item_discount_amt = 0;
+
+ # Gen item_id
+ $item = sqlGenID($db,'invoice_item');
+
# Calculate any recurring discounts for this item
- $item_total_amt = $service->fields['price'];
- $item_discount_amt = $discountObj->calc_all_discounts(1, $item, $service->fields['product_id'], $service->fields['price'], $service->fields['account_id'], $sub_total+$service->fields['price']);
+ $item_total_amt = $service->fields['price'];
+ $item_discount_amt = $discountObj->calc_all_discounts(1,$item,$service->fields['product_id'],$service->fields['price'],$service->fields['account_id'],$sub_total+$service->fields['price']);
$item_total_amt -= $item_discount_amt;
$sub_total += $item_total_amt;
$discount_amt += $item_discount_amt;
-
- # calculate any taxes for this item
- if($service->fields['taxable'] == 1) {
- $item_tax_amt=0;
- $item_tax_arr = $taxObj->calculate($item_total_amt, $service->fields['country_id'], $service->fields['state']);
- if(is_array($item_tax_arr)) foreach($item_tax_arr as $tx) $item_tax_amt += $tx['rate'];
- $tax_amt += $item_tax_amt;
+
+ # Calculate any taxes for this item
+ if ($service->fields['taxable'] == 1) {
+ $item_tax_amt = 0;
+ $item_tax_arr = $taxObj->calculate($item_total_amt,$service->fields['country_id'],$service->fields['state']);
+
+ if (is_array($item_tax_arr))
+ foreach($item_tax_arr as $tx)
+ $item_tax_amt += $tx['rate'];
+
+ $tax_amt += $item_tax_amt;
}
-
+
# Calculate next invoice date
- $next_invoice = $serviceObj->calcNextInvoiceDate($service->fields['date_next_invoice'], $service->fields['recur_schedule'], $service->fields['recur_type'], $service->fields['recur_weekday']);
+ $next_invoice = $serviceObj->calcNextInvoiceDate($service->fields['date_next_invoice'],$service->fields['recur_schedule'],$service->fields['recur_type'],$service->fields['recur_weekday']);
$due_date = $service->fields['date_next_invoice'];
- $recur_schedule=0;
- if(!empty($service->fields['recur_schedule'])) $recur_schedule = $service->fields['recur_schedule'];
-
- // create the invoice item
- $sql="INSERT INTO {$p}invoice_item SET
- id=$item,
- site_id=$s,
- date_orig=".time().",
- invoice_id = $invoice,
- account_id={$service->fields['account_id']},
- service_id={$service->fields['id']},
- product_id={$service->fields['product_id']},
- product_attr=".$db->qstr($service->fields['prod_attr']).",
- product_attr_cart=".$db->qstr($service->fields['prod_attr_cart']).",
- sku=".$db->qstr($service->fields['sku']).",
- quantity=1,
- item_type=0,
- price_type={$service->fields['price_type']},
- price_base={$service->fields['price']},
- price_setup=0,
- recurring_schedule={$recur_schedule},
- date_start={$service->fields['date_next_invoice']},
- date_stop=$next_invoice,
- domain_name=".$db->qstr($service->fields['domain_name']).",
- domain_tld=".$db->qstr($service->fields['domain_tld']).",
- domain_type=".$db->qstr($service->fields['domain_type']).",
- tax_amt=$tax_amt,
- total_amt=$item_total_amt,
- discount_amt=$item_discount_amt";
- $itemrs=$db->Execute($sql);
- if($itemrs === false) {global $C_debug; $C_debug->error('invoice.inc.php','generateInvoices()2', $sql . " \r\n\r\n " . @$db->ErrorMsg()); $db->FailTrans(); return false; }
-
- // Insert tax records
- $taxObj->invoice_item($invoice, $item, $service->fields['account_id'], @$item_tax_arr);
-
+
+ $recur_schedule = 0;
+ if (! empty($service->fields['recur_schedule']))
+ $recur_schedule = $service->fields['recur_schedule'];
+
+ # Create the invoice item
+ $itemrs = $db->Execute(sqlInsert($db,'invoice_item',array(
+ 'date_orig'=>time(),
+ 'invoice_id'=>$invoice,
+ 'account_id'=>$service->fields['account_id'],
+ 'service_id'=>$service->fields['id'],
+ 'product_id'=>$service->fields['product_id'],
+ 'product_attr'=>$service->fields['prod_attr'],
+ 'product_attr_cart'=>$service->fields['prod_attr_cart'],
+ 'sku'=>$service->fields['sku'],
+ 'quantity'=>1,
+ 'item_type'=>0,
+ 'price_type'=>$service->fields['price_type'],
+ 'price_base'=>$service->fields['price'],
+ 'price_setup'=>0,
+ 'recurring_schedule'=>$recur_schedule,
+ 'date_start'=>$service->fields['date_next_invoice'],
+ 'date_stop'=>$next_invoice,
+ 'domain_name'=>$service->fields['domain_name'],
+ 'domain_tld'=>$service->fields['domain_tld'],
+ 'domain_type'=>$service->fields['domain_type'],
+ 'tax_amt'=>$tax_amt,
+ 'total_amt'=>$item_total_amt,
+ 'discount_amt'=>$item_discount_amt
+ ),$item));
+
+ if ($itemrs === false) {
+ global $C_debug;
+
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+ $db->FailTrans();
+
+ return false;
+ }
+
+ # Insert tax records
+ $taxObj->invoice_item($invoice,$item,$service->fields['account_id'],@$item_tax_arr);
+
# Insert discount records
- $discountObj->invoice_item($invoice, $item, $service->fields['account_id'], @$discountObj->discount_arr);
-
- // Update the last & next invoice date for this service
- $sql="UPDATE {$p}service
- SET
- date_last_invoice = {$service->fields['date_next_invoice']},
- date_next_invoice = $next_invoice
- WHERE
- site_id=$s AND id = {$service->fields['id']} ";
- $srvsrs = $db->Execute($sql);
- if($srvsrs === false) {global $C_debug; $C_debug->error('invoice.inc.php','generateInvoices()3', $sql . " \r\n\r\n " . @$db->ErrorMsg()); $db->FailTrans(); return false; }
-
- // get any charges for this service and create them as invoice items
- if($charge_installed) {
+ $discountObj->invoice_item($invoice,$item,$service->fields['account_id'],@$discountObj->discount_arr);
+
+ # Update the last & next invoice date for this service
+ $srvsrs = $db->Execute(sqlUpdate($db,'service',array('date_last_invoice'=>$service->fields['date_next_invoice'],'date_next_invoice'=>$next_invoice),array('id'=>$service->fields['id'])));
+ if ($srvsrs === false) {
+ global $C_debug;
+
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+ $db->FailTrans();
+
+ return false;
+ }
+
+ # Get any charges for this service and create them as invoice items
+ if ($charge_installed) {
$sql = "SELECT * FROM ".AGILE_DB_PREFIX."charge WHERE (status=0 or status is null) and site_id=".DEFAULT_SITE." AND service_id = ".$service->fields['id']." AND date_orig < ". $service->fields['date_next_invoice'];
$charge = $db->Execute($sql);
- if($charge && $charge->RecordCount()) {
- while(!$charge->EOF) {
+ if($charge && $charge->RecordCount()) {
+ while(!$charge->EOF) {
$item_tax_amt=0;
$item_total_amt=0;
$item_discount_amt=0;
-
+
// Calculate any recurring discounts for this charge item
- $item_total_amt = ($charge->fields['quantity']*$charge->fields['amount']);
+ $item_total_amt = ($charge->fields['quantity']*$charge->fields['amount']);
$item_discount_amt = $discountObj->calc_all_discounts(1, $item, $charge->fields['product_id'], $item_total_amt, $service->fields['account_id'], $sub_total+$item_total_amt);
$item_total_amt -= $item_discount_amt;
$sub_total += $item_total_amt;
- $discount_amt += $item_discount_amt;
-
+ $discount_amt += $item_discount_amt;
+
// calculate any taxes for this item
if($charge->fields['taxable'] == 1) {
- $item_tax_amt=0;
- $item_tax_arr = $taxObj->calculate($chargeamt, $service->fields['country_id'], $service->fields['state']);
- if(is_array($item_tax_arr)) foreach($item_tax_arr as $tx) $item_tax_amt += $tx['rate'];
- $tax_amt += $item_tax_amt;
- }
-
+ $item_tax_amt=0;
+ $item_tax_arr = $taxObj->calculate($chargeamt, $service->fields['country_id'], $service->fields['state']);
+ if(is_array($item_tax_arr)) foreach($item_tax_arr as $tx) $item_tax_amt += $tx['rate'];
+ $tax_amt += $item_tax_amt;
+ }
+
// create the invoice item
$charge_item_id = sqlGenID($db, 'invoice_item');
-
- $sql = "INSERT INTO {$p}invoice_item SET
- id = $charge_item_id,
+
+ $sql = "INSERT INTO {$p}invoice_item SET
+ id = $charge_item_id,
site_id = $s,
charge_id = {$charge->fields['id']},
date_orig = ".time().",
- invoice_id = $invoice,
- account_id = ".$this->account_id.",
+ invoice_id = $invoice,
+ account_id = ".$this->account_id.",
service_id = ".$db->qstr($service->fields['id']).",
- product_id = ".$db->qstr($charge->fields['product_id']).",
- product_attr= ".$db->qstr($charge->fields['attributes']).",
- sku = ".$db->qstr($service->fields['sku']).",
- price_base = ".$db->qstr($charge->fields['amount']).",
- quantity = ".$charge->fields['quantity'].",
+ product_id = ".$db->qstr($charge->fields['product_id']).",
+ product_attr= ".$db->qstr($charge->fields['attributes']).",
+ sku = ".$db->qstr($service->fields['sku']).",
+ price_base = ".$db->qstr($charge->fields['amount']).",
+ quantity = ".$charge->fields['quantity'].",
item_type = 5,
price_type = 0,
- price_setup = 0,
- tax_amt = $item_tax_amt,
- total_amt = $item_total_amt,
+ price_setup = 0,
+ tax_amt = $item_tax_amt,
+ total_amt = $item_total_amt,
discount_amt= $item_discount_amt";
- $itemrs=$db->Execute($sql);
+ $itemrs=$db->Execute($sql);
if($itemrs === false) {global $C_debug; $C_debug->error('invoice.inc.php','generateInvoices()4', $sql . " \r\n\r\n " . @$db->ErrorMsg()); $db->FailTrans(); return false; }
-
+
# Insert tax records
- $taxObj->invoice_item($invoice, $charge_item_id, $charge->fields['account_id'], @$item_tax_arr);
-
+ $taxObj->invoice_item($invoice, $charge_item_id, $charge->fields['account_id'], @$item_tax_arr);
+
# Insert discount records
$discountObj->invoice_item($invoice, $charge_item_id, $charge->fields['account_id'], @$discountObj->discount_arr);
-
+
# update charge status
$chargers=$db->Execute("UPDATE ".AGILE_DB_PREFIX."charge set status=1 WHERE id={$charge->fields['id']} AND site_id=".DEFAULT_SITE);
if($chargers === false) {global $C_debug; $C_debug->error('invoice.inc.php','generateInvoices()2', $sql . " \r\n\r\n " . @$db->ErrorMsg()); $db->FailTrans(); return false; }
-
+
$charge->MoveNext();
- }
- }
- }
- $service->MoveNext();
+ }
+ }
+ }
+ $service->MoveNext();
}
-
- // add any taxes
- @$total = $sub_total + $tax_amt;
-
- // get invoice grace period from global/account
- if(!empty($this->invoice_grace)) $grace_period=$this->invoice_grace; else $grace_period=GRACE_PERIOD;
-
- $sql = "INSERT INTO {$p}invoice SET
- id=$invoice,
- site_id=$s,
- date_orig = ".time().",
- date_last = ".time().",
- notice_next_date = ".time().",
- type = 1,
- process_status = 0,
- billing_status = 0,
- suspend_billing = 0,
- print_status = 0,
- refund_status = 0,
- billed_amt = 0,
- actual_billed_amt = 0,
- notice_count = 0,
- parent_id = ".$db->qstr($this->parent_id).",
- account_id = {$this->account_id},
- account_billing_id = ".$db->qstr($this->account_billing_id).",
- affiliate_id = ".$db->qstr($this->affiliate_id).",
- campaign_id = ".$db->qstr($this->campaign_id).",
- reseller_id = ".$db->qstr($this->reseller_id).",
- checkout_plugin_id = ".$db->qstr($this->checkout_plugin_id).",
- checkout_plugin_data = ".$db->qstr($this->checkout_plugin_data).",
- actual_billed_currency_id = ".$db->qstr($this->actual_billed_currency_id).",
- billed_currency_id = ".$db->qstr($this->billed_currency_id).",
- notice_max = ".$db->qstr(MAX_BILLING_NOTICE).",
- grace_period = ".$db->qstr($grace_period).",
- tax_amt = ".$tax_amt.",
- discount_amt = ".$discount_amt.",
- total_amt = ".$total.",
- due_date = $due_date";
- $invoicers=$db->Execute($sql);
- if($invoicers === false) {global $C_debug; $C_debug->error('invoice.inc.php','generateInvoices()2', $sql . " \r\n\r\n " . @$db->ErrorMsg()); $db->FailTrans(); return false; }
- }
-
- if(AGILE_DB_TYPE == 'mysqlt') $db->CompleteTrans();
+
+ # Add any taxes
+ $total = $sub_total+$tax_amt;
+
+ # Get invoice grace period from global/account
+ if (! empty($this->invoice_grace))
+ $grace_period = $this->invoice_grace;
+ else
+ $grace_period = GRACE_PERIOD;
+
+ $invoicers = $db->Execute($a=sqlInsert($db,'invoice',array(
+ 'date_orig'=>time(),
+ 'date_last'=>time(),
+ 'notice_next_date'=>time(),
+ 'type'=>1,
+ 'process_status'=>0,
+ 'billing_status'=>0,
+ 'suspend_billing'=>0,
+ 'print_status'=>0,
+ 'refund_status'=>0,
+ 'billed_amt'=>0,
+ 'actual_billed_amt'=>0,
+ 'notice_count'=>0,
+ 'parent_id'=>$this->parent_id,
+ 'account_id'=>$this->account_id,
+ 'account_billing_id'=>$this->account_billing_id,
+ 'affiliate_id'=>$this->affiliate_id,
+ 'campaign_id'=>$this->campaign_id,
+ 'reseller_id'=>$this->reseller_id,
+ 'checkout_plugin_id'=>$this->checkout_plugin_id,
+ 'checkout_plugin_data'=>$this->checkout_plugin_data,
+ 'actual_billed_currency_id'=>$this->actual_billed_currency_id,
+ 'billed_currency_id'=>$this->billed_currency_id,
+ 'notice_max'=>MAX_BILLING_NOTICE,
+ 'grace_period'=>$grace_period,
+ 'tax_amt'=>$tax_amt,
+ 'discount_amt'=>$discount_amt,
+ 'total_amt'=>$total,
+ 'due_date'=>$due_date
+ ),$invoice));
+
+ if ($invoicers === false) {
+ global $C_debug;
+
+ $C_debug->error(__FILE__,__METHOD__,$db->ErrorMsg());
+ $db->FailTrans();
+
+ return false;
+ }
+ }
+
+ if (AGILE_DB_TYPE == 'mysqlt')
+ $db->CompleteTrans();
}
-
-
-
-
- /** Invoice expiring domains
+
+ /** Invoice expiring domains
*/
function generateDomains()
- {
+ {
$db = &DB();
define('DEFAULT_DOMAIN_INVOICE', 30); //how far out to generate expiring domain invoices
$expire = time() + (DEFAULT_DOMAIN_INVOICE*86400);
-
+
### Get domains expiring soon:
$rs = $db->Execute( sqlSelect( $db, 'service', '*', " active=1 AND domain_date_expire <= $expire AND type = 'domain' AND queue = 'none' AND
( domain_type = 'register' OR domain_type = 'transfer' OR domain_type = 'renew' ) AND
( suspend_billing = 0 OR suspend_billing IS NULL) " ) );
-
+
if($rs && $rs->RecordCount() > 0 ) {
while(!$rs->EOF) {
# Check that this domain has not already been invoiced
- $invoiced = $db->Execute( sqlSelect ($db, Array('invoice_item','invoice'), Array('A.*','B.*'),
+ $invoiced = $db->Execute(sqlSelect ($db, array('invoice_item','invoice'), array('A.*','B.*'),
" A.invoice_id = B.id AND A.service_id = {$rs->fields['id']} AND A.sku = 'DOMAIN-RENEW' AND domain_type = 'renew' AND
- date_start = {$rs->fields['date_last_invoice']} AND date_stop = {$rs->fields['domain_date_expire']}" ) );
-
+ date_start = {$rs->fields['date_last_invoice']} AND date_stop = {$rs->fields['domain_date_expire']}" ) );
+
if($invoiced && $invoiced->RecordCount() == 0) {
# Not previously invoiced, generate now!
$this->generatedomaininvoice( $rs->fields, $this );
- }
+ }
$rs->MoveNext();
}
}
}
-
- /** Invoice expiring domains p2
+
+ /** Invoice expiring domains p2
*/
- function generatedomaininvoice( $VAR )
+ function generatedomaininvoice($VAR)
{
include_once(PATH_MODULES . 'tax/tax.inc.php');
$taxObj = new tax;
-
+
$db = &DB();
-
+
if( is_array( $VAR ) ) {
$expire = time();
- $rs = $db->Execute( sqlSelect($db, 'service', '*', " id = ::{$VAR['id']}:: AND active=1
+ $rs = $db->Execute(sqlSelect($db, 'service', '*', " id = ::{$VAR['id']}:: AND active=1
AND type = 'domain' AND queue = 'none' AND
- ( domain_type = 'register' OR domain_type = 'transfer' OR domain_type = 'renew' ) AND
- ( suspend_billing = 0 OR suspend_billing IS NULL ) " ));
+ (domain_type = 'register' OR domain_type = 'transfer' OR domain_type = 'renew') AND
+ (suspend_billing = 0 OR suspend_billing IS NULL) "));
$service = $rs->fields;
} else {
$service = $VAR;
- }
-
+ }
+
if(empty($service['id'])) {
global $C_debug;
$C_debug->alert("Unable to generate domain renweal invoice due to domain status.");
return false;
}
-
+
# Get the parent invoice details:
if(!empty($service['invoice_id'])) {
- $rs = $db->Execute( sqlSelect($db, 'invoice', '*', " id = {$service['invoice_id']} ", "" ) );
+ $rs = $db->Execute(sqlSelect($db, 'invoice', '*', " id = {$service['invoice_id']} ", ""));
$invoice = $rs->fields;
} else {
$invoice = false;
}
-
+
# Get the account details:
- $rs = $db->Execute( sqlSelect($db, 'account', '*', " id = {$service['account_id']} ", "" ) );
+ $rs = $db->Execute(sqlSelect($db, 'account', '*', " id = {$service['account_id']} ", ""));
$account = $rs->fields;
-
+
# Get the account price
include_once(PATH_MODULES.'host_tld/host_tld.inc.php');
- $tldObj=new host_tld;
- $tld_arr = $tldObj->price_tld_arr($service['domain_tld'], 'renew', false, false, false, $service['account_id']);
+ $tldObj=new host_tld;
+ $tld_arr = $tldObj->price_tld_arr($service['domain_tld'], 'renew', false, false, false, $service['account_id']);
foreach($tld_arr as $term => $price) break;
-
+
# Calculate taxes:
- $rs = $db->Execute($sql=sqlSelect($db,"host_tld","taxable","name = ::{$service['domain_tld']}::"));
+ $rs = $db->Execute($sql=sqlSelect($db,"host_tld","taxable","name = ::{$service['domain_tld']}::"));
if( $service['taxable'] || @$rs->fields['taxable'] ) {
$tax_arr = $taxObj->calculate($price, $account["country_id"], $account["state"]);
} else {
$tax_arr = false;
}
-
+
$total = $price;
-
+
$tax_amt = 0;
if(is_array($tax_arr)) {
foreach($tax_arr as $tx) {
@@ -2626,15 +2979,15 @@ class invoice
}
$total += $tax_amt;
}
-
+
# calculate the dates
$expire = $service['domain_date_expire'] + ($term*86400);
$due_date = $service['domain_date_expire'] - (86400*3);
-
+
# Create the invoice
- $id = sqlGenID( $db, "invoice" );
- $insert = $db->Execute( $sql = sqlInsert($db, "invoice",
- Array(
+ $id = sqlGenID($db, "invoice");
+ $insert = $db->Execute($sql = sqlInsert($db, "invoice",
+ array(
'date_orig' => time(),
'date_last' => time(),
'type' => 2,
@@ -2662,12 +3015,12 @@ class invoice
'notice_max' => MAX_BILLING_NOTICE,
'grace_period' => 0,
'due_date' => $due_date
- ), $id ) ) ;
-
+ ), $id)) ;
+
# create the invoice item:
if($insert) {
- $db->Execute ( $idx = sqlInsert($db, "invoice_item",
- Array(
+ $db->Execute ($idx = sqlInsert($db, "invoice_item",
+ array(
'date_orig' => time(),
'invoice_id' => $id,
'account_id' => $service['account_id'],
@@ -2686,22 +3039,22 @@ class invoice
'domain_term' => $term,
'tax_amt' => $tax_amt,
'total_amt' => $price
- ) ) );
-
+ )));
+
# Insert tax records
- $taxObj->invoice_item($id, $idx, $service['account_id'], @$item_tax_arr);
-
+ $taxObj->invoice_item($id, $idx, $service['account_id'], @$item_tax_arr);
+
# Update the service record
- $fields=Array('active' => 0);
+ $fields=array('active' => 0);
$db->Execute(sqlUpdate($db,"service",$fields,"id = {$service['id']}"));
-
+
global $C_debug;
$C_debug->alert("Generated domain renewal invoice for {$service['domain_name']}.{$service['domain_tld']}");
return $id;
}
}
-
-
+
+
/** Run AutoBilling and Due Notices
*/
@@ -2714,21 +3067,21 @@ class invoice
$mail = new email_template;
# get all due invoices
- $db = &DB();
+ $db = &DB();
#$db->debug = true;
-
+
if(empty($VAR['invoice_id']))
{
$this->bill_one = false;
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'invoice
- WHERE notice_next_date <= ' . $db->qstr( time() ) . '
+ WHERE notice_next_date <= ' . $db->qstr( time() ) . '
AND (
billing_status = 0 OR
billing_status IS NULL
- ) AND (
+ ) AND (
suspend_billing = 0 OR
suspend_billing IS NULL
- )
+ )
AND site_id = ' . $db->qstr(DEFAULT_SITE);
$invoice = $db->Execute($sql);
if($invoice->RecordCount() == 0) {
@@ -2742,7 +3095,7 @@ class invoice
WHERE (
billing_status = 0 OR
billing_status IS NULL
- )
+ )
AND id = ' . $db->qstr($VAR['invoice_id']) . '
AND site_id = ' . $db->qstr(DEFAULT_SITE);
$invoice = $db->Execute($sql);
@@ -2758,7 +3111,7 @@ class invoice
while(!$invoice->EOF)
{
$db->StartTrans();
-
+
$due = true;
# get currency code
@@ -2770,7 +3123,7 @@ class invoice
id = ". $db->qstr($cyid)." AND
site_id = ". $db->qstr(DEFAULT_SITE);
$currb = $db->Execute($q);
- $this->format_currency[$cyid] = Array ( 'convert' => unserialize($currb->fields["convert_array"]),
+ $this->format_currency[$cyid] = array('convert' => unserialize($currb->fields["convert_array"]),
'iso' => $currb->fields["three_digit"]);
}
@@ -2782,12 +3135,12 @@ class invoice
id = ".$db->qstr($billed_currency_id)." AND
site_id = ".$db->qstr(DEFAULT_SITE);
$currb = $db->Execute($q);
- $this->format_currency[$billed_currency_id] = Array ( 'convert' => unserialize($currb->fields["convert_array"]),
+ $this->format_currency[$billed_currency_id] = array('convert' => unserialize($currb->fields["convert_array"]),
'iso' => $currb->fields["three_digit"]);
}
# attempt to autobill?
- if(!empty( $invoice->fields['account_billing_id'] ))
+ if(!empty($invoice->fields['account_billing_id']))
{
# get checkout plugin details:
$billing =& $db->Execute($sql=sqlSelect($db, array('account_billing','checkout'), 'A.*,B.checkout_plugin',
@@ -2797,14 +3150,14 @@ class invoice
$plugin_file = PATH_PLUGINS.'checkout/'. $billing->fields['checkout_plugin'] .'.php';
if(!is_file($plugin_file)) {
$err = $plugin_file .' missing when autobilling invoice id ' . $invoice->fields['id'];
- $C_debug->error('invoice.inc.php','autobill()', $err);
+ $C_debug->error(__FILE__,__METHOD__,$err);
} else {
- include_once ( $plugin_file );
- eval( '$PLG = new plg_chout_' . $billing->fields['checkout_plugin'] . '("'.$billing->fields['checkout_plugin_id'].'");');
+ include_once ($plugin_file);
+ eval('$PLG = new plg_chout_' . $billing->fields['checkout_plugin'] . '("'.$billing->fields['checkout_plugin_id'].'");');
}
} else {
$err = 'account_billing.id '.$invoice->fields['account_billing_id'].' empty or not associated with a checkout plugin when autobilling invoice id ' . $invoice->fields['id'];
- $C_debug->error('invoice.inc.php','autobill()', $err);
+ $C_debug->error(__FILE__,__METHOD__,$err);
}
}
@@ -2815,26 +3168,26 @@ class invoice
if($amount <= 0) $due = false;
if(!empty($PLG) && is_object($PLG) && $PLG->type == 'gateway' && $amount > 0)
- {
+ {
# attempt autobilling if account billing exists and gateway plugin
- if($invoice->fields['account_billing_id'] > 0 )
+ if($invoice->fields['account_billing_id'] > 0)
{
/* get the account details */
$account = $db->Execute(sqlSelect($db,"account","id,email","id=::{$invoice->fields['account_id']}"));
-
+
/* Convert the invoice amount to the actual billed currency amount */
- if($cyid != $invoice->fields['billed_currency_id']) {
+ if($cyid != $invoice->fields['billed_currency_id']) {
$conversion = $this->format_currency[$billed_currency_id]["convert"][$cyid]["rate"];
$amount *= $conversion;
$actual_billed_amt = $invoice->fields['actual_billed_amt'] + $amount;
}
-
- /* load the billing details from the database */
+
+ /* load the billing details from the database */
$PLG->setBillingFromDBObj($billing, true);
-
+
/* attempt to auto-bill */
if(!$checkout_plugin_data = $PLG->bill_checkout( number_format($amount,2), $invoice->fields['id'], $this->format_currency[$cyid]['iso'], $account->fields, 0,0) ) {
- $due = true;
+ $due = true;
$email = new email_template;
$email->send('invoice_decline_user', $invoice->fields['account_id'], $invoice->fields['id'],$C_list->format_currency($invoice->fields['total_amt'],$cyid), $C_list->date($invoice->fields['due_date']));
$email = new email_template;
@@ -2884,7 +3237,7 @@ class invoice
notice_count = ' . $db->qstr($invoice->fields['notice_count']+1) . ',
notice_next_date = ' . $db->qstr(time()+86400*3) . '
WHERE
- id = ' . $db->qstr( $invoice->fields['id'] ) . ' AND
+ id = ' . $db->qstr($invoice->fields['id']) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$db->Execute($sql);
}
@@ -2905,10 +3258,10 @@ class invoice
notice_count = ' . $db->qstr($invoice->fields['notice_count']+1) . ',
suspend_billing = ' . $db->qstr('1') . '
WHERE
- id = ' . $db->qstr( $invoice->fields['id'] ) . ' AND
+ id = ' . $db->qstr($invoice->fields['id']) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
- $db->Execute($sql);
- }
+ $db->Execute($sql);
+ }
}
else
{
@@ -2919,7 +3272,7 @@ class invoice
billed_amt = ' . $db->qstr($billed_amt) . ',
actual_billed_amt = ' . $db->qstr($actual_billed_amt) . '
WHERE
- id = ' . $db->qstr( $invoice->fields['id'] ) . ' AND
+ id = ' . $db->qstr($invoice->fields['id']) . ' AND
site_id = ' . $db->qstr(DEFAULT_SITE);
$db->Execute($sql);
@@ -2936,168 +3289,180 @@ class invoice
}
$invoice->MoveNext();
unset($PLG);
-
+
/* finish transaction */
$db->CompleteTrans();
}
}
-
-
/**
* Find out if a user has unpaid invoices
*/
- function has_unpaid($VAR) {
- if(!SESS_LOGGED) return false;
- $db=&DB();
- $inv=$db->Execute($sql=sqlSelect($db,"invoice","SUM(total_amt-billed_amt) as total",
- "account_id=".SESS_ACCOUNT." AND billing_status=0 AND refund_status=0"));
- if($inv && $inv->RecordCount() && $inv->fields['total']>0) {
- global $smarty, $C_list;
- //$act= $db->Execute(sqlSelect($db,"account","currency_id","id=));
- $smarty->assign('has_unpaid', $C_list->format_currency_num($inv->fields['total'],SESS_CURRENCY));
- }
+ public function has_unpaid($VAR) {
+ global $smarty, $C_list;
+
+ if (! SESS_LOGGED)
+ return false;
+
+ $total = 0;
+ foreach ($this->unpaid(SESS_ACCOUNT) as $amount)
+ $total += $amount;
+
+ if ($total)
+ $smarty->assign('has_unpaid',$C_list->format_currency_num($total,SESS_CURRENCY));
}
-
/**
* Get the totals for multiple invoices or for a group of invoices stored in temp
+ *
+ * The retrieved invoice numbers are stored in $this->invoice;
+ *
+ * @param string If invoice is 'MULTI-*', get unpaid invoices from the temporary_data table, otherwise
+ * get the unpaid invoices listed, or all invoices if blank.
*/
- function multiple_invoice_total($invoice,$account_id=SESS_ACCOUNT)
- {
+ private function multiple_invoice_total($invoice,$account_id=SESS_ACCOUNT) {
+ $this->invoice = array();
$db = &DB();
- if(empty($invoice) || eregi(",", $invoice)) {
+
+ if (! preg_match('/^MULTI-/',$invoice)) {
$id_list='';
- if(!empty($invoice)) {
- $id = explode(',', $invoice);
- for($i=0; $iqstr($id[$i])." ";
- $ii++;
- } else {
- $id_list .= " OR id = " .$db->qstr($id[$i]). " ";
- $ii++;
- }
- }
- }
- if(!empty($id_list)) $id_list = "( $id_list ) AND ";
- }
- // get invoice totals
- $total=0;
- $inv=$db->Execute($sql=sqlSelect($db,"invoice","id,total_amt,billed_amt", "$id_list account_id=".SESS_ACCOUNT." AND billing_status=0 AND refund_status=0"));
- if($inv && $inv->RecordCount()) {
- while(!$inv->EOF) {
- $this->invoice[] = $inv->fields['id'];
- $total += ($inv->fields['total_amt']-$inv->fields['billed_amt']);
- $inv->MoveNext();
+
+ if ($invoice = preg_replace('/,$/','',$invoice))
+ $id_list = sprintf('id in (%s) AND',$invoice);
+
+ # Get invoice totals
+ $total = 0;
+ $rs = $db->Execute(sqlSelect($db,'invoice','id,total_amt,billed_amt',sprintf('%s account_id=%s AND billing_status=0 AND refund_status=0',$id_list,SESS_ACCOUNT)));
+ if ($rs && $rs->RecordCount()) {
+ while (! $rs->EOF) {
+ $this->invoice[$rs->fields['id']] = $rs->fields['total_amt']-$rs->fields['billed_amt'];
+ $total += $this->invoice[$rs->fields['id']];
+ $rs->MoveNext();
}
+
return $total;
- } else {
- return false;
}
+
} else {
- // get total from temp data
- $inv=$db->Execute($sql=sqlSelect($db,"temporary_data","data,field1 as total","field2=::$invoice::"));
- if($inv && $inv->RecordCount() && $inv->fields['total'] > 0) {
- if(!empty($inv->fields['field2'])) $this->invoice=unserialize($inv->fields['data']);
- return $inv->fields['total'];
- } else {
- return false;
- }
+ # Get total from temp data
+ $rs = $db->Execute(sqlSelect($db,'temporary_data','data,field1',array('field2'=>$invoice)));
+ if ($rs && $rs->RecordCount() && $rs->fields['field1'] > 0) {
+ $this->invoice = unserialize($rs->fields['data']);
+ return $rs->fields['field1'];
+ }
}
- return false;
+
+ return false;
}
/**
* Preview checkout of multiple invoices
*/
- function checkout_multiple_preview($VAR)
- {
+ public function tpl_checkout_multiple_preview($VAR) {
global $smarty,$C_list;
- if(!SESS_LOGGED) return false;
-
- $db=&DB();
- $total = $this->multiple_invoice_total(@$VAR['id'],SESS_ACCOUNT);
- if($total > 0 && count($this->invoice) > 1)
- {
- // get country id for checkout options
- $account=sqlSelect($db, "account", "country_id", "id=".SESS_ACCOUNT);
-
- // get payment options
+
+ if (! SESS_LOGGED)
+ return false;
+
+ # If the ID is blank, this will get all unpaid invoices.
+ if (! isset($VAR['id']))
+ $VAR['id'] = '';
+
+ $total = $this->multiple_invoice_total($VAR['id'],SESS_ACCOUNT);
+ $db = &DB();
+
+ if ($total > 0 && count($this->invoice) > 1) {
+ # Get country id for checkout options
+ $account = $db->Execute(sqlSelect($db,'account','country_id',array('id'=>SESS_ACCOUNT)));
+
+ # Get payment options
include_once(PATH_MODULES.'checkout/checkout.inc.php');
$checkout = new checkout;
- $checkoutoptions = $checkout->get_checkout_options(SESS_ACCOUNT, $total, false, $account->fields['country_id'],true);
-
- // get a temporary id (48 hours)
- $id=sqlGenID($db, "temporary_data");
- $invoice["id"] = "MULTI-$id";
- $invoice["total"] = $total;
- $fields=Array('date_orig'=>time(), 'date_expire'=>time()+86400*3, 'field2'=> $invoice['id'], 'field1'=>$total, 'data'=>serialize($this->invoice));
- $id = & $db->Execute(sqlInsert($db,"temporary_data",$fields));
-
- $smarty->assign('invoice', $invoice);
- $smarty->assign('total', $C_list->format_currency_num($total,SESS_CURRENCY));
- $smarty->assign('checkoutoptions', $checkoutoptions);
-
- } elseif (count($this->invoice) == 1) {
- $id = $this->invoice[0];
- echo "";
+
+ $checkoutoptions = $checkout->get_checkout_options(SESS_ACCOUNT,$total,false,$account->fields['country_id'],true);
+
+ # Get a temporary id (48 hours)
+ $id = sqlGenID($db,'temporary_data');
+ $invoice['id'] = sprintf('MULTI-%s',$id);
+ $invoice['total'] = $total;
+
+ $fields = array('date_orig'=>time(),'date_expire'=>time()+86400*3,'field2'=>$invoice['id'],'field1'=>$total,'data'=>serialize($this->invoice));
+ $rs = $db->Execute($q=sqlInsert($db,'temporary_data',$fields,$id));
+
+ $smarty->assign('record',$invoice);
+ $smarty->assign('total',$C_list->format_currency_num($total,SESS_CURRENCY));
+ $smarty->assign('checkoutoptions',$checkoutoptions);
+
+ } elseif (count($this->invoice) == 1) {
+ printf("",key($this->invoice));
+
} else {
- echo "No due invoices selected for payment.";
+ echo _('No due invoices selected for payment.');
}
}
-
-
- /** Run checkout plugin for billing
- */
- function checkoutnow($VAR)
- {
- global $C_translate, $smarty, $C_list, $VAR;
-
+
+
+ /**
+ * Make a payment now
+ */
+ public function checkoutnow($VAR) {
+ global $C_translate,$smarty,$C_list,$VAR;
+
# Validate user logged in:
- if(SESS_LOGGED != '1') {
- echo '';
+ if (SESS_LOGGED != '1') {
+ echo '';
return false;
}
-
- $db = &DB();
- if(eregi("MULTI-", @$VAR['invoice_id'])) {
- // get multi-invoice details
- $total = $this->multiple_invoice_total(@$VAR['invoice_id'],SESS_ACCOUNT);
- if(!$total) return false;
- $recur_amt=false;
- $recur_arr=false;
- $account_id=SESS_ACCOUNT;
- $this->invoice[]=$VAR['invoice_id'];
- $this->invoice_id=$VAR['invoice_id'];
+
+ # If the ID is blank, this will get all unpaid invoices.
+ if (! isset($VAR['invoice_id']))
+ return false;
+
+ # Some defaults
+ $recur_amt = 0;
+
+ $db = &DB();
+ if(preg_match('/^MULTI-/',@$VAR['invoice_id'])) {
+ # Get multi-invoice details
+ $total = $this->multiple_invoice_total($VAR['invoice_id'],SESS_ACCOUNT);
+ if (! $total)
+ return false;
+
+ $recur_arr = false;
+ $account_id = SESS_ACCOUNT;
+ $this->invoice_id = $VAR['invoice_id'];
$CURRENCY = DEFAULT_CURRENCY;
- $multi=true;
+ $multi = true;
+
} else {
# Validate the invoice selected, & get the totals:
- $sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'invoice WHERE site_id = '.$db->qstr(DEFAULT_SITE).' AND id = ' . $db->qstr($VAR['invoice_id']);
- $result = $db->Execute($sql);
- if(!$result || $result->RecordCount() == 0) return false;
-
+ $result = $db->Execute($q=sqlSelect($db,'invoice','*',array('id'=>$VAR['invoice_id'])));
+ if (! $result || $result->RecordCount() == 0)
+ return false;
+
# Determine the price & currency
- if($result->fields['billed_currency_id'] != $result->fields['actual_billed_currency_id']) {
+ if ($result->fields['billed_currency_id'] != $result->fields['actual_billed_currency_id']) {
global $C_list;
+
$CURRENCY = $result->fields['actual_billed_currency_id'];
if($result->fields['billed_amt'] <= 0)
- $total = $C_list->format_currency_decimal ($result->fields['total_amt'], $CURRENCY);
+ $total = $C_list->format_currency_decimal($result->fields['total_amt'],$CURRENCY);
else
- $total = $C_list->format_currency_decimal ($result->fields['total_amt'], $CURRENCY) - $result->fields['actual_billed_amt'];
+ $total = $C_list->format_currency_decimal($result->fields['total_amt'],$CURRENCY)-$result->fields['actual_billed_amt'];
+
} else {
$CURRENCY = $result->fields['billed_currency_id'];
$total = $result->fields['total_amt']-$result->fields['billed_amt'];
}
- $recur_amt=$result->fields['recur_amt'];
- if($recur_amt>0) $recur_amt = $C_list->format_currency_decimal ($recur_amt, $CURRENCY);
- @$recur_arr=unserialize($result->fields['recur_arr']);
- $account_id=$result->fields['account_id'];
- $this->invoice_id=$result->fields['id'];
- $this->invoice[]=$result->fields['id'];
- $multi=false;
+
+ if ($result->fields['recur_amt'] > 0)
+ $recur_amt = $C_list->format_currency_decimal($result->fields['recur_amt'],$CURRENCY);
+
+ @$recur_arr = unserialize($result->fields['recur_arr']);
+ $account_id = $result->fields['account_id'];
+ $this->invoice_id = $result->fields['id'];
+ $this->invoice[$result->fields['id']] = $total;
+ $multi = false;
}
$amount = round($total, 2);
@@ -3105,31 +3470,31 @@ class invoice
$sql = 'SELECT * FROM ' . AGILE_DB_PREFIX . 'account WHERE site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND id = ' . $db->qstr($account_id);
$account = $db->Execute($sql);
if (!$account || !$account->RecordCount()) return false;
-
+
# Validate checkout option selected is allowed for purchase:
$q = "SELECT * FROM ".AGILE_DB_PREFIX."checkout WHERE site_id = ".$db->qstr(DEFAULT_SITE)." AND id = ".$db->qstr(@$VAR['option'])." AND active = 1 AND ";
- if($recur_amt>0 && @$billed_amt == 0 ) $q .= "allow_recurring = 1 "; else $q .= "allow_new = 1 ";
+ if($recur_amt>0 && @$billed_amt == 0) $q .= "allow_recurring = 1 "; else $q .= "allow_new = 1 ";
$chopt = $db->Execute($q);
if (!$chopt || !$chopt->RecordCount()) return false;
if($chopt && $chopt->RecordCount()) {
$show = true;
- if ( @$chopt->fields["total_maximum"] != "" && $total > $chopt->fields["total_maximum"] ) $show = false;
- if ( @$chopt->fields["total_miniumum"] != "" && $total < $chopt->fields["total_miniumum"] ) $show = false;
+ if ( @$chopt->fields["total_maximum"] != "" && $total > $chopt->fields["total_maximum"] ) $show = false;
+ if ( @$chopt->fields["total_miniumum"] != "" && $total < $chopt->fields["total_miniumum"] ) $show = false;
}
if(!$show) {
echo ' ';
return false;
- }
-
+ }
+
# Load the checkout plugin:
$plugin_file = PATH_PLUGINS . 'checkout/'. $chopt->fields["checkout_plugin"] . '.php';
include_once ( $plugin_file );
- eval ( '$PLG = new plg_chout_' . $chopt->fields["checkout_plugin"] . '("'.@$VAR["option"].'");');
-
- if(!empty($VAR['account_billing_id']) && @$VAR['new_card']==2) {
+ eval ( '$PLG = new plg_chout_' . $chopt->fields["checkout_plugin"] . '("'.@$VAR["option"].'",$multi);');
+
+ if(!empty($VAR['account_billing_id']) && @$VAR['new_card']==2) {
/* validate credit card on file details */
- $account_billing_id=$VAR['account_billing_id'];
- if(!$PLG->setBillingFromDB($account_id, $account_billing_id, $VAR['option'])) {
+ $account_billing_id=$VAR['account_billing_id'];
+ if(!$PLG->setBillingFromDB($account_id, $account_billing_id, $VAR['option'])) {
global $C_debug;
$C_debug->alert("Sorry, we cannot use that billing record for this purchase.");
return false;
@@ -3138,38 +3503,39 @@ class invoice
/* use passed in vars */
$PLG->setBillingFromParams($VAR);
}
-
+
# Set Invoice Vars:
$this->total_amt = $amount;
$this->currency_iso = $C_list->currency_iso($CURRENCY);
- $this->currency_iso_admin = $C_list->currency_iso($CURRENCY);
- $this->account_id = $account_id;
+ $this->currency_iso_admin = $C_list->currency_iso($CURRENCY);
+ $this->account_id = $account_id;
$this->actual_billed_currency_id = $CURRENCY;
$this->billed_currency_id = $CURRENCY;
$this->checkout_plugin_id = @$VAR["option"];
-
+
# Run the plugin bill_checkout() method:
- $this->checkout_plugin_data = $PLG->bill_checkout( $amount, $this->invoice_id, $this->currency_iso, $account->fields, $recur_amt, $recur_arr);
+ $this->checkout_plugin_data = $PLG->bill_checkout($amount, $this->invoice_id, $this->currency_iso, $account->fields, $recur_amt, $recur_arr,$this->invoice);
# redirect
if(!empty($this->checkout_plugin_data['redirect'])) echo $this->checkout_plugin_data['redirect'];
-
+
# determine results
if( $this->checkout_plugin_data === false ) {
- if(!empty($PLG->redirect)) echo $PLG->redirect;
- return false;
- } elseif ($PLG->type == "gateway" && empty($PLG->redirect)) {
+ if(!empty($PLG->redirect)) echo $PLG->redirect;
+ return false;
+ } elseif ($PLG->type == "gateway" && empty($PLG->redirect)) {
if(empty($this->admin_checkout)) {
$VAR['_page'] = "invoice:thankyou";
} else {
$VAR['_page'] = "invoice:view";
- }
+ }
} elseif ($PLG->type == "redirect") {
+
echo "
Please wait while we redirect you to the secure payment site....
- {$PLG->redirect} ";
- }
-
+ {$PLG->redirect}