Example #1
0
    public function pre_menu()
    {
        if ($this->can_i('view', 'Members')) {
            // how many members are there?
            $link_name = _l('Members');
            if (module_config::c('member_show_summary', 1)) {
                $member_count = module_cache::get('member', 'member_menu_count');
                if ($member_count === false) {
                    $sql = "SELECT COUNT(member_id) AS c FROM `" . _DB_PREFIX . "member` m";
                    $res = qa1($sql);
                    $member_count = $res['c'];
                    module_cache::put('member', 'member_menu_count', $member_count);
                }
                if ($member_count > 0) {
                    $link_name .= " <span class='menu_label'>" . $member_count . "</span> ";
                }
            }
            $this->links['members'] = array("name" => $link_name, "p" => "member_admin", "args" => array('member_id' => false));
            if (class_exists('module_newsletter', false) && module_config::c('member_menu_under_newsletter', 1)) {
                $this->links['members']['holder_module'] = 'newsletter';
                $this->links['members']['holder_module_page'] = 'newsletter_admin';
                $this->links['members']['menu_include_parent'] = 0;
                $this->links['members']['allow_nesting'] = 1;
            }
        }
        if (class_exists('module_template', false)) {
            module_template::init_template('member_subscription_form', '<h2>Subscribe</h2>
<form action="" method="post">
    <p>Please Enter Your Email Address: <input type="text" name="member[email]" value="{EMAIL}"> </p>
    <p>Please Enter Your First Name: <input type="text" name="member[first_name]" value="{FIRST_NAME}"> </p>
    <p>Please Enter Your Last Name: <input type="text" name="member[last_name]" value="{LAST_NAME}"> </p>
    <p>Please Enter Your Business Name: <input type="text" name="member[business]" value="{BUSINESS}"> </p>
    <p>Please Enter Your Phone Number: <input type="text" name="member[phone]" value="{PHONE}"> </p>
    <p>
    Please choose your newsletter subscription options: <br/>
    {NEWSLETTER_OPTIONS}
    </p>
    <p><input type="submit" name="confirm" value="Subscribe"></p>
</form>
    ', 'Used when a user wishes to subscribe.', 'code', array());
            module_template::init_template('member_subscription_error', '<h2>Subscription Error</h2>
    <p>Sorry there was an error when processing your request:</p>
    <p>{MESSAGE}</p>
    ', 'Displayed when subscription fails (eg: missing email address).', 'code', array('MESSAGE' => 'Message to the user'));
            module_template::init_template('member_subscription_success', '<h2>Subscription Success</h2>
    <p>Thank you, subscription successful.</p>
    <p>A message has been sent to your email address ({EMAIL}) to confirm your newsletter subscription.</p>
    ', 'Displayed when subscription is successful.', 'code', array('EMAIL' => 'Users email address'));
            module_template::init_template('member_update_details_success', '<h2>Subscription Success</h2>
    <p>Thank you, subscription details updated.</p>
    <p>Your email address: ({EMAIL})</p>
    ', 'Displayed when updating details is successful.', 'code', array('EMAIL' => 'Users email address'));
        }
    }
Example #2
0
 function next_record_id()
 {
     $sql = "SELECT LAST_INSERT_ID(data_field_id) AS `boob` FROM `" . _DB_PREFIX . "data_field` LIMIT 1";
     $res = qa1($sql);
     return $res['boob'];
 }
            $sql = "SELECT * FROM `" . _DB_PREFIX . "language_word` WHERE `word` = '" . mysql_real_escape_string($translation['translation']) . "'";
            $res = qa($sql);
            if (count($res)) {
                //echo $sql.'<br>';
            }
            foreach ($res as $r) {
                $duplicate_word_ids[$r['language_word_id']] = $translation['translation'];
            }
        }
        if (module_language::ignore_word($translation['word'])) {
            $duplicate_word_ids[$translation['language_word_id']] = $translation['translation'];
        }
    }
    foreach ($duplicate_word_ids as $duplicate_word_id => $tf) {
        $sql = "SELECT * FROM `" . _DB_PREFIX . "language_word` WHERE `language_word_id` = " . (int) $duplicate_word_id;
        $translation = qa1($sql);
        ?>
		        <tr>
		            <td>

		                <?php 
        echo htmlspecialchars($translation['word']);
        ?>
		            </td>
		            <td>
		                <?php 
        echo htmlspecialchars($tf);
        ?>
		            </td>
		        </tr>
	            <?php 
Example #4
0
 public static function get_statistics_staff($search)
 {
     $staff_members = module_user::get_staff_members();
     $statistics = array();
     foreach ($staff_members as $staff_member) {
         $statistics[$staff_member['user_id']] = array('user_id' => $staff_member['user_id'], 'job_ids' => array(), 'job_count' => 0, 'task_count' => 0, 'task_ids' => array(), 'task_complete_ids' => array(), 'tasks_complete' => 0, 'hours_logged' => 0, 'hours_billed' => 0, 'amount_billed' => 0, 'amount_invoiced' => 0);
         $sql = "SELECT COUNT(j.job_id) AS job_count ";
         $sql .= " FROM `" . _DB_PREFIX . "job` j";
         $sql .= " WHERE j.user_id = " . (int) $staff_member['user_id'];
         if (isset($search['date_from']) && $search['date_from']) {
             $sql .= " AND j.date_start >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to']) {
             $sql .= " AND j.date_start <= '" . input_date($search['date_to']) . "'";
         }
         $res = qa1($sql);
         $statistics[$staff_member['user_id']]['job_count'] = $res['job_count'];
         $sql = "SELECT COUNT(t.task_id) AS task_count ";
         $sql .= " FROM `" . _DB_PREFIX . "task` t";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` j ON t.job_id = j.job_id";
         $sql .= " WHERE 1";
         $sql .= " AND t.user_id = " . (int) $staff_member['user_id'];
         if (isset($search['date_from']) && $search['date_from']) {
             $sql .= " AND j.date_start >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to']) {
             $sql .= " AND j.date_start <= '" . input_date($search['date_to']) . "'";
         }
         $res = qa1($sql);
         $statistics[$staff_member['user_id']]['task_count'] = $res['task_count'];
         // tasks completed on this date:
         $sql = "SELECT COUNT(t.task_id) AS task_count ";
         $sql .= " FROM `" . _DB_PREFIX . "task` t";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` j ON t.job_id = j.job_id";
         $sql .= " WHERE 1";
         $sql .= " AND t.user_id = " . (int) $staff_member['user_id'];
         if (isset($search['date_from']) && $search['date_from']) {
             $sql .= " AND t.date_done >= '" . input_date($search['date_from']) . "'";
         }
         if (isset($search['date_to']) && $search['date_to']) {
             $sql .= " AND t.date_done <= '" . input_date($search['date_to']) . "'";
         }
         $res = qa1($sql);
         $statistics[$staff_member['user_id']]['tasks_complete'] = $res['task_count'];
         $sql = "SELECT t.task_id, tl.date_created, t.hours AS task_hours, t.amount, tl.hours AS hours_logged, p.job_id, p.hourly_rate ";
         $sql .= ", tl.create_user_id AS logged_user_id";
         $sql .= " FROM `" . _DB_PREFIX . "task_log` tl ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "task` t ON tl.task_id = t.task_id ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "job` p ON tl.job_id = p.job_id";
         $sql .= " WHERE 1 ";
         $sql .= " AND ( tl.create_user_id = " . (int) $staff_member['user_id'] . " )";
         //t.user_id = ".(int)$staff_member['user_id'] . " OR
         if (isset($search['date_from']) && $search['date_from']) {
             $sql .= " AND tl.log_time >= '" . strtotime(input_date($search['date_from']) . " 00:00:00") . "'";
         }
         if (isset($search['date_to']) && $search['date_to']) {
             $sql .= " AND tl.log_time <= '" . strtotime(input_date($search['date_to']) . " 23:59:59") . "'";
         }
         //echo $sql;
         $tasks = query($sql);
         while ($r = mysql_fetch_assoc($tasks)) {
             //print_r($r);
             $jobtasks = module_job::get_tasks($r['job_id']);
             $statistics[$staff_member['user_id']]['job_ids'][$r['job_id']] = true;
             $task = $jobtasks[$r['task_id']];
             // this user has been assiged to this job individual task.
             if ($task['fully_completed']) {
                 $statistics[$staff_member['user_id']]['task_complete_ids'][$r['task_id']] = true;
                 $statistics[$staff_member['user_id']]['hours_billed'] += $r['task_hours'];
                 if ($task['amount'] > 0) {
                     $statistics[$staff_member['user_id']]['amount_billed'] += $task['amount'];
                 } else {
                     $statistics[$staff_member['user_id']]['amount_billed'] += $r['task_hours'] * $r['hourly_rate'];
                 }
                 $sql = "SELECT  * FROM `" . _DB_PREFIX . "invoice_item` ii WHERE ii.task_id = " . (int) $r['task_id'];
                 $task_invoice = qa1($sql);
                 if ($task_invoice && $task_invoice['task_id'] == $r['task_id']) {
                     if ($task_invoice['amount'] > 0) {
                         $statistics[$staff_member['user_id']]['amount_invoiced'] += $task_invoice['amount'];
                     } else {
                         $statistics[$staff_member['user_id']]['amount_invoiced'] += $task_invoice['hours'] * $task_invoice['hourly_rate'];
                     }
                 }
             }
             $statistics[$staff_member['user_id']]['task_ids'][$r['task_id']] = true;
             $statistics[$staff_member['user_id']]['hours_logged'] += $r['hours_logged'];
         }
         //$statistics[$staff_member['user_id']]['job_count'] = count($statistics[$staff_member['user_id']]['job_ids']);
     }
     return $statistics;
 }
Example #5
0
 public static function get_company($company_id)
 {
     $company = array();
     if ((int) $company_id > 0) {
         $where = 'WHERE 1 AND c.company_id = ' . (int) $company_id;
         $sql = "SELECT c.*, c.company_id AS id ";
         $sql .= " FROM `" . _DB_PREFIX . "company` c ";
         $company_access = self::get_company_data_access();
         switch ($company_access) {
             case _COMPANY_ACCESS_ALL:
                 break;
             case _COMPANY_ACCESS_ASSIGNED:
                 // we only want companies that are directly linked with the currently logged in user contact (from the staff user account settings area)
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_user_rel` cur ON c.company_id = cur.company_id ";
                 $where .= " AND (cur.user_id = " . (int) module_security::get_loggedin_id() . ")";
                 break;
             case _COMPANY_ACCESS_CONTACT:
                 // only parent company of current user account contact
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_customer` cc ON c.company_id = cc.company_id ";
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "user` u ON cc.customer_id = u.customer_id ";
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "company_vendor` cv ON c.company_id = cv.company_id ";
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "user` uv ON cv.vendor_id = uv.vendor_id ";
                 $where .= " AND (u.user_id = " . (int) module_security::get_loggedin_id() . " OR uv.user_id = " . (int) module_security::get_loggedin_id() . ")";
                 break;
         }
         $sql .= $where;
         $company = qa1($sql);
     }
     return $company;
 }
Example #6
0
 public static function process_login($redirect = true, $captcha_check = true)
 {
     if ($captcha_check && module_config::c('login_recaptcha', 0)) {
         // ignore captcha check from auto_login call (sets $captcha_check=false)
         if (!module_captcha::check_captcha_form()) {
             // captcha was wrong.
             set_error('Sorry the captcha code you entered was incorrect. Please try again.');
             return;
             //_e('Sorry the captcha code you entered was incorrect. Please <a href="%s" onclick="%s">go back</a> and try again.','#','window.history.go(-1); return false;');
             //exit;
         }
     }
     $email = trim($_REQUEST['email']);
     $password = trim($_REQUEST['password']);
     $_SESSION['_AVA_logged_in'] = false;
     if (strlen($email) && strlen($password)) {
         // a user logs in, and they can access a certain areas of the website based on their permissions.
         // each user is assigned a site.
         // all data in the system is related to a particular site.
         // we store the users current site id in the system.
         // this way when the security 'sanatise' option runs we know which site_id to place into newly created date and
         // which site_id's the user can access if they are not super admins
         // update! we match hashed passwords, as well as unhashed passwords.
         $sql = "SELECT * FROM `" . _DB_PREFIX . "user` WHERE `email` LIKE '" . mysql_real_escape_string($email) . "' AND ( `password` = '" . mysql_real_escape_string($password) . "' OR `password` = '" . mysql_real_escape_string(md5($password)) . "' )";
         $res = qa1($sql);
         if (strlen(trim($res['email'])) > 0 && strtolower($res['email']) == strtolower($email)) {
             // check the status of the user.
             // not sure what this will do.
             if (isset($res['linked_parent_user_id']) && $res['linked_parent_user_id'] > 0) {
                 // swap to this user
                 $parent_user = module_user::get_user($res['linked_parent_user_id'], false, false);
                 if ($parent_user && $res['linked_parent_user_id'] == $parent_user['user_id']) {
                     // login as this user instead.
                     $res = $parent_user;
                 }
             }
             //if(!$res['status_id'] && $res['user_id']!=1){ // 0 is inactive. 1 is active.
             // check this user has permissions to login.
             if ($res['user_id'] != 1 && !self::can_user_login($res['user_id'])) {
                 set_error('Account disabled');
                 if ($redirect) {
                     $_SERVER['REQUEST_URI'] = preg_replace('/auto_login=[^&]*&?/', '', $_SERVER['REQUEST_URI']);
                     redirect_browser($_SERVER['REQUEST_URI']);
                 }
                 return false;
             }
             $_SESSION['_AVA_logged_in'] = true;
             // todo - find out all their links.
             /*if(isset($res['linked_parent_user_id']) && $res['linked_parent_user_id'] == $res['user_id']){
                                 // this user is a primary user.
                                 $_SESSION['_restrict_customer_id'] = array();
                                 $_SESSION['_restrict_customer_id'][$res['customer_id']] = $res['customer_id'];
                                 foreach(module_user::get_contact_customer_links($res['user_id']) as $linked){
                                     $_SESSION['_restrict_customer_id'][$linked['customer_id']] = $linked['customer_id'];
                                 }
             
             
                             }else{
                                 // oldschool permissions.
                                 $_SESSION['_restrict_customer_id'] = $res['customer_id'];
                             }*/
             // find the access level from the security_access table.
             /*$level = self::get_access_level($res['user_id']);
             		$_SESSION['_access_level'] = $level['access_level'];
             		$_SESSION['_data_access'] = $level['data_access'];*/
             $sql = "INSERT INTO `" . _DB_PREFIX . "security_login` SET user_id = '" . $res['user_id'] . "', `time` = '" . time() . "', ip_address = '" . $_SERVER['REMOTE_ADDR'] . "'";
             query($sql);
             $_SESSION['_user_name'] = $res['name'];
             $_SESSION['_user_email'] = $res['email'];
             $_SESSION['_user_id'] = $res['user_id'];
             /*if(!$res['user_type_id']){
                               $res['user_type_id'] = 2; // default to a 'contact' ..
                               module_user::set_user_type($res['user_id'],2);
                           }
             		$_SESSION['_user_type_id'] = $res['user_type_id'];*/
             $_SESSION['_language'] = $res['language'];
             set_message(_l("You have successfully logged in."));
             if ($redirect) {
                 $_SERVER['REQUEST_URI'] = preg_replace('/auto_login=[^&]*&?/', '', $_SERVER['REQUEST_URI']);
                 redirect_browser($_SERVER['REQUEST_URI']);
                 exit;
             }
             return true;
         }
     }
     set_error('Invalid username or password, please try again.');
     return true;
 }
Example #7
0
    public function get_upgrade_sql()
    {
        $sql = '';
        $res = qa1("SHOW TABLES LIKE '" . _DB_PREFIX . "ticket_data'");
        if (!$res || !count($res)) {
            $sql .= "CREATE TABLE IF NOT EXISTS `" . _DB_PREFIX . "ticket_data` (\r\r\n    `ticket_data_id` int(11) NOT NULL AUTO_INCREMENT,\r\r\n    `ticket_data_key_id` int(11) NOT NULL,\r\r\n    `ticket_id` int(11) NOT NULL,\r\r\n    `value` text NOT NULL,\r\r\n    `create_user_id` int(11) NOT NULL,\r\r\n    `update_user_id` int(11) NOT NULL,\r\r\n    `date_updated` date NOT NULL,\r\r\n    `date_created` int(11) NOT NULL,\r\r\n    PRIMARY KEY (`ticket_data_id`)\r\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;";
        }
        $res = qa1("SHOW TABLES LIKE '" . _DB_PREFIX . "ticket_data_key'");
        if (!$res || !count($res)) {
            $sql .= "CREATE TABLE IF NOT EXISTS `" . _DB_PREFIX . "ticket_data_key` (\r\r\n              `ticket_data_key_id` int(11) NOT NULL AUTO_INCREMENT,\r\r\n              `ticket_account_id` int(11) NOT NULL,\r\r\n              `key` varchar(255) NOT NULL,\r\r\n              `type` varchar(50) NOT NULL,\r\r\n              `options` text NOT NULL,\r\r\n              `order` int(11) NOT NULL DEFAULT '0',\r\r\n                `encrypt_key_id` int(11) NOT NULL DEFAULT '0',\r\r\n              `create_user_id` int(11) NOT NULL,\r\r\n              `update_user_id` int(11) NOT NULL,\r\r\n              `date_updated` date NOT NULL,\r\r\n              `date_created` int(11) NOT NULL,\r\r\n              PRIMARY KEY (`ticket_data_key_id`)\r\r\n            ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;";
        }
        $res = qa1("SHOW TABLES LIKE '" . _DB_PREFIX . "ticket_message_attachment'");
        if (!$res || !count($res)) {
            $sql_create = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX . 'ticket_message_attachment` (
              `ticket_message_attachment_id` int(11) NOT NULL AUTO_INCREMENT,
              `ticket_id` int(11) DEFAULT NULL,
              `ticket_message_id` int(11) DEFAULT NULL,
              `file_name` varchar(255) NOT NULL,
              `content_type` varchar(60) NOT NULL,
              `create_user_id` int(11) NOT NULL,
              `update_user_id` int(11) NULL,
              `date_created` date NOT NULL,
              `date_updated` date NULL,
              PRIMARY KEY (`ticket_message_attachment_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;';
            query($sql_create);
        }
        $res = qa1("SHOW TABLES LIKE '" . _DB_PREFIX . "ticket_type'");
        if (!$res || !count($res)) {
            $sql_create = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX . 'ticket_type` (
              `ticket_type_id` int(11) NOT NULL AUTO_INCREMENT,
              `name` varchar(255) NOT NULL,
              `public` tinyint(1) NOT NULL DEFAULT \'0\',
              `create_user_id` int(11) NOT NULL,
              `update_user_id` int(11) NOT NULL,
              `date_updated` date NOT NULL,
              `date_created` int(11) NOT NULL,
              PRIMARY KEY (`ticket_type_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
            ';
            query($sql_create);
        }
        $fields = get_fields('ticket_data_key');
        if (!isset($fields['encrypt_key_id'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'ticket_data_key` ADD `encrypt_key_id` int(11) NOT NULL DEFAULT \'0\' AFTER  `order`;';
        }
        $fields = get_fields('ticket');
        if (!isset($fields['priority'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'ticket` ADD `priority` INT NOT NULL DEFAULT  \'0\' AFTER  `user_id`;';
        }
        if (!isset($fields['invoice_id'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'ticket` ADD `invoice_id` INT NOT NULL DEFAULT  \'0\' AFTER  `user_id`;';
        }
        if (!isset($fields['faq_product_id'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'ticket` ADD `faq_product_id` INT NOT NULL DEFAULT  \'0\' AFTER  `ticket_account_id`;';
        }
        $fields = get_fields('ticket');
        if (!isset($fields['ticket_type_id'])) {
            $ticket_type_sql = 'ALTER TABLE `' . _DB_PREFIX . 'ticket` ADD `ticket_type_id` INT NOT NULL DEFAULT  \'0\' AFTER  `type`;';
            query($ticket_type_sql);
            // upgrade our ticket types into this new table.
            $sql_old_types = "SELECT `type` FROM `" . _DB_PREFIX . "ticket` GROUP BY `type` ORDER BY `type`";
            $statuses = array();
            foreach (qa($sql_old_types) as $r) {
                if (strlen(trim($r['type'])) > 0) {
                    $ticket_type_id = update_insert('ticket_type_id', 'new', 'ticket_type', array('name' => $r['type']));
                    $sql_ticket_type_id = "UPDATE `" . _DB_PREFIX . "ticket` SET ticket_type_id = '" . (int) $ticket_type_id . "' WHERE `type` = '" . mysql_real_escape_string($r['type']) . "'";
                    query($sql_ticket_type_id);
                }
            }
        }
        $fields = get_fields('ticket_message');
        if (!isset($fields['create_user_id'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'ticket_message` ADD `create_user_id` INT NOT NULL DEFAULT  \'0\';';
        }
        if (!isset($fields['private_message'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'ticket_message` ADD `private_message` tinyint(1) NOT NULL DEFAULT  \'0\' AFTER `status_id`;';
        }
        $fields = get_fields('ticket_type');
        if (!isset($fields['default_user_id'])) {
            $sql .= 'ALTER TABLE `' . _DB_PREFIX . 'ticket_type` ADD `default_user_id` INT(11) NOT NULL DEFAULT  \'0\';';
        }
        if (!$this->db_table_exists('ticket_quote_rel')) {
            $sql .= 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX . 'ticket_quote_rel` (
			    `ticket_id` int(11) NOT NULL,
			    `quote_id` int(11) NOT NULL,
			    PRIMARY KEY (`ticket_id`, `quote_id`)
			    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ;
            ';
        }
        // todo - other tables.
        self::add_table_index('ticket', 'assigned_user_id');
        self::add_table_index('ticket', 'ticket_account_id');
        self::add_table_index('ticket', 'last_message_timestamp');
        self::add_table_index('ticket', 'status_id');
        self::add_table_index('ticket', 'user_id');
        self::add_table_index('ticket', 'customer_id');
        self::add_table_index('ticket', 'faq_product_id');
        return $sql;
    }
Example #8
0
 public static function get_recurring($finance_recurring_id)
 {
     // show last transaction etc..
     $finance_recurring_id = (int) $finance_recurring_id;
     if ($finance_recurring_id > 0) {
         //return get_single('finance_recurring','finance_recurring_id',$finance_recurring_id);
         $sql = "SELECT r.*  ";
         $sql .= ", f.amount AS last_amount ";
         $sql .= ", f.transaction_date AS last_transaction_date ";
         $sql .= ", f.finance_id AS last_transaction_finance_id ";
         $sql .= " , fa.name AS account_name ";
         $sql .= " , (SELECT GROUP_CONCAT(fc.`name` ORDER BY fc.`name` ASC SEPARATOR ', ') FROM `" . _DB_PREFIX . "finance_recurring_catrel` fcr LEFT JOIN `" . _DB_PREFIX . "finance_category` fc ON fcr.finance_category_id = fc.finance_category_id WHERE fcr.finance_recurring_id = r.finance_recurring_id) AS categories";
         $sql .= " FROM `" . _DB_PREFIX . "finance_recurring` r ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance` f ON r.finance_recurring_id = f.finance_recurring_id ";
         $sql .= " LEFT JOIN `" . _DB_PREFIX . "finance_account` fa ON r.finance_account_id = fa.finance_account_id ";
         $sql .= " WHERE 1";
         $sql .= " AND ( f.finance_id IS NULL or f.finance_id = (SELECT ff.finance_id FROM `" . _DB_PREFIX . "finance` ff WHERE ff.finance_recurring_id = r.finance_recurring_id ORDER BY transaction_date DESC LIMIT 1) )";
         $sql .= " AND r.finance_recurring_id = {$finance_recurring_id}";
         $recurring = qa1($sql);
         $recurring['category_ids'] = get_multiple('finance_recurring_catrel', array('finance_recurring_id' => $finance_recurring_id), 'finance_category_id');
         return $recurring;
     } else {
         return array('name' => '', 'description' => '', 'finance_account_id' => '', 'start_date' => '', 'end_date' => '', 'amount' => '', 'currency_id' => module_config::c('default_currency_id', 1), 'days' => '0', 'months' => '0', 'years' => '0', 'type' => 'e', 'category_ids' => array());
     }
 }
Example #9
0
    public function output_block($level)
    {
        if (!$this->get('social_twitter_message_id') || $level < -3) {
            return;
        }
        $twitter_data = @json_decode($this->get('data'), true);
        // any previous messages?
        if ($level <= 0) {
            if ($this->get('reply_to_id')) {
                // this tweet is a reply to a previous tweet!
                ?>
				<div class="twitter_previous_messages">
					<?php 
                $reply_message = new ucm_twitter_message($this->twitter_account, $this->get('reply_to_id'));
                $reply_message->output_block($level - 1);
                ?>
				</div>
				<?php 
            } else {
                if ($this->get('type') == _TWITTER_MESSAGE_TYPE_DIRECT) {
                    // find previous message(s)
                    $from = preg_replace('#[^0-9]#', '', $this->get('twitter_from_id'));
                    $to = preg_replace('#[^0-9]#', '', $this->get('twitter_to_id'));
                    if ($from && $to) {
                        $sql = "SELECT * FROM `" . _DB_PREFIX . "social_twitter_message` WHERE `type` = " . _TWITTER_MESSAGE_TYPE_DIRECT . " AND message_time <= " . (int) $this->get('message_time') . " AND social_twitter_message_id != " . (int) $this->social_twitter_message_id . " AND ( (`twitter_from_id` = {$from} AND `twitter_to_id` = {$to}) OR (`twitter_from_id` = {$to} AND `twitter_to_id` = {$from}) ) ORDER BY `message_time` DESC LIMIT 1";
                        $previous = qa1($sql);
                        if ($previous && $previous['social_twitter_message_id']) {
                            ?>
						<div class="twitter_previous_messages twitter_direct">
							<?php 
                            $reply_message = new ucm_twitter_message($this->twitter_account, $previous['social_twitter_message_id']);
                            $reply_message->output_block($level - 1);
                            ?>
						</div>
						<?php 
                        }
                    }
                }
            }
        }
        $message_from = isset($twitter_data['user']) ? $twitter_data['user'] : (isset($twitter_data['sender']) ? $twitter_data['sender'] : false);
        if ($this->get('summary')) {
            if ($message_from && $this->get('type') != _TWITTER_MESSAGE_TYPE_DIRECT) {
                $message_from['tweet_id'] = isset($twitter_data['id_str']) ? $twitter_data['id_str'] : false;
            }
            //echo '<pre>'; print_r($twitter_data); echo '</pre>';
            ?>
			<div class="twitter_comment <?php 
            echo $level != 0 ? ' twitter_comment_clickable' : 'twitter_comment_current';
            ?>
" data-id="<?php 
            echo $this->social_twitter_message_id;
            ?>
" data-link="<?php 
            echo module_social_twitter::link_open_twitter_message($this->get('social_twitter_id'), $this->social_twitter_message_id);
            ?>
" data-title="<?php 
            echo _l('Tweet');
            ?>
">
				<div class="twitter_comment_picture">
					<?php 
            if (isset($twitter_data['user']['id_str'])) {
                $pic = array('screen_name' => isset($twitter_data['user']['screen_name']) ? $twitter_data['user']['screen_name'] : '', 'image' => isset($twitter_data['user']['profile_image_url_https']) ? $twitter_data['user']['profile_image_url_https'] : '');
            } else {
                if (isset($twitter_data['sender']['id_str'])) {
                    $pic = array('screen_name' => isset($twitter_data['sender']['screen_name']) ? $twitter_data['sender']['screen_name'] : '', 'image' => isset($twitter_data['sender']['profile_image_url_https']) ? $twitter_data['sender']['profile_image_url_https'] : '');
                } else {
                    $pic = false;
                }
            }
            if ($pic) {
                ?>
						<img src="<?php 
                echo $pic['image'];
                ?>
">
						<?php 
            }
            ?>
				</div>
				<div class="twitter_comment_header">
					<?php 
            _e('From:');
            echo ' ';
            echo $message_from ? ucm_twitter::format_person($message_from) : 'N/A';
            ?>
					<span><?php 
            $time = strtotime($this->get('message_time'));
            echo $time ? ' @ ' . print_date($time, true) : '';
            if ($this->get('user_id')) {
                echo ' (sent by ' . module_user::link_open($this->get('user_id'), true) . ')';
            }
            ?>
					</span>
				</div>
				<div class="twitter_comment_body">
					<?php 
            if (isset($twitter_data['entities']['media']) && is_array($twitter_data['entities']['media'])) {
                foreach ($twitter_data['entities']['media'] as $media) {
                    if ($media['type'] == 'photo') {
                        ?>
								<div class="twitter_picture">
									<?php 
                        if (isset($media['url']) && $media['url']) {
                            ?>
 <a
										href="<?php 
                            echo htmlspecialchars($media['url']);
                            ?>
"
										target="_blank"> <?php 
                        }
                        ?>
										<img src="<?php 
                        echo htmlspecialchars($media['media_url_https']);
                        ?>
">
										<?php 
                        if (isset($media['url']) && $media['url']) {
                            ?>
 </a> <?php 
                        }
                        ?>
								</div>
							<?php 
                    }
                }
            }
            ?>
					<div>
						<?php 
            echo forum_text($this->get('summary'));
            ?>
					</div>
					<div class="twitter_comment_stats">
						<?php 
            $data = @json_decode($this->get('data'), true);
            //print_r($data);
            if ($data && (isset($data['retweet_count']) && $data['retweet_count'] > 0 || isset($data['favorite_count']) && $data['favorite_count'] > 0)) {
                if (isset($data['retweet_count']) && $data['retweet_count'] > 0) {
                    echo _l('Retweets: %s', $data['retweet_count']);
                }
                echo ' ';
                if (isset($data['favorite_count']) && $data['favorite_count'] > 0) {
                    echo _l('Favorites: %s', $data['favorite_count']);
                }
            }
            ?>
					</div>
				</div>
				<div class="twitter_comment_actions">
					<?php 
            if ($this->can_reply) {
                ?>
						<a href="#" class="twitter_reply_button"><?php 
                _e('Reply');
                ?>
</a>
					<?php 
            }
            ?>
				</div>
			</div>
		<?php 
        }
        ?>
		<?php 
        if ($level == 0) {
            ?>
			<div class="twitter_comment_replies">
			<?php 
            //if(strpos($twitter_data['message'],'picture')){
            //echo '<pre>'; print_r($twitter_data); echo '</pre>';
            //}
            if ($this->can_reply) {
                $this->reply_box($level, $message_from);
            }
            ?>
			</div>
		<?php 
        }
        if ($level >= 0) {
            // any follow up messages?
            if ($this->get('type') == _TWITTER_MESSAGE_TYPE_DIRECT) {
                $from = preg_replace('#[^0-9]#', '', $this->get('twitter_from_id'));
                $to = preg_replace('#[^0-9]#', '', $this->get('twitter_to_id'));
                if ($from && $to) {
                    $sql = "SELECT * FROM `" . _DB_PREFIX . "social_twitter_message` WHERE `type` = " . _TWITTER_MESSAGE_TYPE_DIRECT . " AND message_time >= " . (int) $this->get('message_time') . " AND social_twitter_message_id != " . (int) $this->social_twitter_message_id . " AND ( (`twitter_from_id` = {$from} AND `twitter_to_id` = {$to}) OR (`twitter_from_id` = {$to} AND `twitter_to_id` = {$from}) ) ORDER BY `message_time` ASC LIMIT 1";
                    $next = qa1($sql);
                    if ($next && $next['social_twitter_message_id']) {
                        ?>
						<div class="twitter_next_messages twitter_direct">
							<?php 
                        $reply_message = new ucm_twitter_message($this->twitter_account, $next['social_twitter_message_id']);
                        $reply_message->output_block($level + 1);
                        ?>
						</div>
						<?php 
                    }
                }
            } else {
                $next = get_multiple('social_twitter_message', array('social_twitter_id' => $this->twitter_account->get('social_twitter_id'), 'reply_to_id' => $this->social_twitter_message_id), 'social_twitter_message_id');
                if ($next) {
                    foreach ($next as $n) {
                        // this tweet is a reply to a previous tweet!
                        if ($n['social_twitter_message_id']) {
                            ?>
							<div class="twitter_next_messages">
								<?php 
                            $reply_message = new ucm_twitter_message($this->twitter_account, $n['social_twitter_message_id']);
                            $reply_message->output_block($level + 1);
                            ?>
							</div>
							<?php 
                        }
                    }
                }
            }
        }
    }
Example #10
0
 /**
  * @static
  * @param $args
  * @return array
  *
  * The newsletter system requests updated customer / user data from this group plugin.
  * It does this when building the member list, and also 
  */
 public static function newsletter_callback($args)
 {
     if (!isset($args['owner_table']) || !$args['owner_table']) {
         return array();
     }
     switch ($args['owner_table']) {
         case 'user':
             if ((int) $args['owner_id'] > 0) {
                 $sql = "SELECT c.customer_name AS company_name, c.customer_name AS customer_name";
                 $sql .= " , pu.user_id ";
                 $sql .= " , c.customer_id ";
                 $sql .= " ,c.credit ";
                 $sql .= " , pu.name AS user_name, pu.name AS first_name, pu.last_name AS last_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`";
                 $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code ";
                 $sql .= ' FROM `' . _DB_PREFIX . "user` pu";
                 $sql .= " LEFT JOIN `" . _DB_PREFIX . "customer` c ON pu.customer_id = c.customer_id";
                 $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'";
                 $sql .= " WHERE pu.user_id = " . (int) $args['owner_id'];
                 $user = qa1($sql);
                 if (!is_array($user) || !isset($user['user_id']) || !$user['user_id']) {
                     return false;
                 }
                 if (isset($args['basic']) && $args['basic']) {
                     return $user;
                 }
                 //                    $name_parts = explode(" ",preg_replace('/\s+/',' ',$user['user_name']));
                 //                    $user['first_name'] = array_shift($name_parts);
                 //                    $user['last_name'] = implode(' ',$name_parts);
                 // get extras for the user.
                 $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id']));
                 foreach ($extras as $extra) {
                     if (!strlen(trim($extra['extra']))) {
                         continue;
                     }
                     $key = $extra['extra_key'];
                     $x = 1;
                     while (isset($user[$key])) {
                         $key = $extra['extra_key'] . $x;
                         $x++;
                     }
                     $user[$key] = trim($extra['extra']);
                 }
                 // get extras for the customer.
                 if (isset($user['customer_id']) && $user['customer_id'] > 0) {
                     $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id']));
                     foreach ($extras as $extra) {
                         if (!strlen(trim($extra['extra']))) {
                             continue;
                         }
                         $key = $extra['extra_key'];
                         $x = 1;
                         while (isset($user[$key])) {
                             $key = $extra['extra_key'] . $x;
                             $x++;
                         }
                         $user[$key] = trim($extra['extra']);
                     }
                 }
                 if ($user['customer_id']) {
                     $user['_edit_link'] = module_user::link_open_contact($user['user_id'], false, $user);
                 } else {
                     $user['_edit_link'] = module_user::link_open($user['user_id'], false, $user);
                 }
                 return $user;
             }
             break;
         case 'customer':
             if (module_config::c('newsletter_send_all_customer_contacts', 1)) {
                 // update - we use the above 'user' callback and return a listing for each contact in the array.
                 // using the special _multi flag hack to tell our newsletter plugin that this result contains multiple entries.
                 $users = array('_multi' => true);
                 $sql = "SELECT u.user_id FROM `" . _DB_PREFIX . "user` u WHERE u.customer_id = " . (int) $args['owner_id'];
                 $contacts = qa($sql);
                 foreach ($contacts as $contact) {
                     $data_args = array('owner_id' => $contact['user_id'], 'owner_table' => 'user');
                     $users[$contact['user_id']] = self::newsletter_callback($data_args);
                     if ($users[$contact['user_id']]) {
                         $users[$contact['user_id']]['data_args'] = json_encode($data_args);
                     }
                 }
                 return $users;
             } else {
                 $sql = "SELECT c.customer_name AS company_name, c.customer_name AS customer_name";
                 $sql .= " ,c.credit ";
                 $sql .= " , pu.user_id ";
                 $sql .= " , c.customer_id ";
                 $sql .= " , pu.name AS user_name, pu.name AS first_name, pu.last_name AS last_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`";
                 $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code ";
                 $sql .= " FROM `" . _DB_PREFIX . "customer` c ";
                 $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'";
                 $sql .= ' LEFT JOIN `' . _DB_PREFIX . "user` pu ON c.primary_user_id = pu.user_id";
                 $sql .= " WHERE c.customer_id = " . (int) $args['owner_id'];
                 $user = qa1($sql);
                 if (!$user || !isset($user['customer_id'])) {
                     return array();
                 }
                 //$name_parts = explode(" ",preg_replace('/\s+/',' ',$user['user_name']));
                 //$user['first_name'] = array_shift($name_parts);
                 //$user['last_name'] = implode(' ',$name_parts);
                 if (isset($args['basic']) && $args['basic']) {
                     return $user;
                 }
                 // get extras for the customer.
                 $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id']));
                 foreach ($extras as $extra) {
                     if (!strlen(trim($extra['extra']))) {
                         continue;
                     }
                     $key = $extra['extra_key'];
                     $x = 1;
                     while (isset($user[$key])) {
                         $key = $extra['extra_key'] . $x;
                         $x++;
                     }
                     $user[$key] = trim($extra['extra']);
                 }
                 if (isset($user['user_id']) && $user['user_id'] > 0) {
                     // get extras for the user.
                     $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id']));
                     foreach ($extras as $extra) {
                         if (!strlen(trim($extra['extra']))) {
                             continue;
                         }
                         $key = $extra['extra_key'];
                         $x = 1;
                         while (isset($user[$key])) {
                             $key = $extra['extra_key'] . $x;
                             $x++;
                         }
                         $user[$key] = trim($extra['extra']);
                     }
                 }
                 $user['_edit_link'] = module_customer::link_open($user['customer_id'], false, $user);
                 return $user;
             }
         case 'website':
             $sql = "SELECT c.customer_name AS company_name";
             $sql .= " ,c.credit ";
             $sql .= " ,w.name AS website_name";
             $sql .= " ,w.url AS website_url";
             $sql .= " , pu.user_id ";
             $sql .= " , c.customer_id ";
             $sql .= " , pu.name AS user_name, pu.phone AS phone, pu.`email` AS `email`, pu.`mobile` AS `mobile`";
             $sql .= " , a.line_1, a.line_2, a.suburb, a.state, a.region, a.country, a.post_code ";
             $sql .= " FROM `" . _DB_PREFIX . "website` w ";
             $sql .= ' LEFT JOIN `' . _DB_PREFIX . "customer` c ON w.customer_id = c.customer_id";
             $sql .= ' LEFT JOIN `' . _DB_PREFIX . "address` a ON c.customer_id = a.owner_id AND a.owner_table = 'customer' AND a.address_type = 'physical'";
             $sql .= ' LEFT JOIN `' . _DB_PREFIX . "user` pu ON c.primary_user_id = pu.user_id";
             $sql .= " WHERE w.website_id = " . (int) $args['owner_id'];
             $user = qa1($sql);
             $name_parts = explode(" ", preg_replace('/\\s+/', ' ', $user['user_name']));
             $user['first_name'] = array_shift($name_parts);
             $user['last_name'] = implode(' ', $name_parts);
             if (isset($args['basic']) && $args['basic']) {
                 return $user;
             }
             // get extras for the website.
             $extras = module_extra::get_extras(array('owner_table' => 'website', 'owner_id' => $args['owner_id']));
             foreach ($extras as $extra) {
                 if (!strlen(trim($extra['extra']))) {
                     continue;
                 }
                 $key = $extra['extra_key'];
                 $x = 1;
                 while (isset($user[$key])) {
                     $key = $extra['extra_key'] . $x;
                     $x++;
                 }
                 $user[$key] = trim($extra['extra']);
             }
             // then get extras for the company
             $extras = module_extra::get_extras(array('owner_table' => 'customer', 'owner_id' => $user['customer_id']));
             foreach ($extras as $extra) {
                 if (!strlen(trim($extra['extra']))) {
                     continue;
                 }
                 $key = $extra['extra_key'];
                 $x = 1;
                 while (isset($user[$key])) {
                     $key = $extra['extra_key'] . $x;
                     $x++;
                 }
                 $user[$key] = trim($extra['extra']);
             }
             if (isset($user['user_id']) && $user['user_id'] > 0) {
                 // get extras for the user.
                 $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $user['user_id']));
                 foreach ($extras as $extra) {
                     if (!strlen(trim($extra['extra']))) {
                         continue;
                     }
                     $key = $extra['extra_key'];
                     $x = 1;
                     while (isset($user[$key])) {
                         $key = $extra['extra_key'] . $x;
                         $x++;
                     }
                     $user[$key] = trim($extra['extra']);
                 }
             }
             $user['_edit_link'] = module_customer::link_open($user['customer_id'], false, $user);
             return $user;
         case 'ticket':
             //echo 'Getting ticket for '.$args['owner_id'] . ' and basic is '.var_export($args['basic'],true);exit;
             return module_ticket::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']);
         case 'member':
             return module_member::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']);
         case 'newsletter_subscription':
             return module_member::get_newsletter_recipient($args['owner_id'], isset($args['basic']) && $args['basic']);
     }
     return array();
 }
Example #11
0
 public function get_upgrade_sql()
 {
     $sql = '';
     $fields = get_fields('user');
     if (!isset($fields['last_name'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'user` ADD  `last_name` VARCHAR( 90 ) NOT NULL DEFAULT  \'\' AFTER  `name`;';
     }
     if (!isset($fields['vendor_id'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'user` ADD  `vendor_id` INT( 11 ) NOT NULL DEFAULT  \'0\' AFTER  `customer_id`;';
     }
     if (!isset($fields['linked_parent_user_id'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'user` ADD  `linked_parent_user_id` INT( 11 ) NOT NULL DEFAULT  \'0\' AFTER  `customer_id`;';
     }
     if (!isset($fields['is_staff'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'user` ADD  `is_staff` TINYINT(2) NOT NULL DEFAULT  \'-1\' AFTER  `status_id`;';
     }
     if (!isset($fields['split_hours'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'user` ADD  `split_hours` TINYINT(2) NOT NULL DEFAULT  \'0\' AFTER  `is_staff`;';
     }
     if (!isset($fields['hourly_rate'])) {
         $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'user` ADD  `hourly_rate` DECIMAL(10,2) NOT NULL DEFAULT  \'0\' AFTER  `split_hours`;';
     }
     // check for indexes
     self::add_table_index('user', 'customer_id');
     self::add_table_index('user', 'vendor_id');
     self::add_table_index('user', 'linked_parent_user_id');
     self::add_table_index('user', 'is_staff');
     /*$sql_check = 'SHOW INDEX FROM `'._DB_PREFIX.'user';
             $res = qa($sql_check);
             //print_r($res);exit;
             $add_index=true;
             foreach($res as $r){
                 if(isset($r['Column_name']) && $r['Column_name'] == 'customer_id'){
                     $add_index=false;
                 }
             }
             if($add_index){
                 $sql .= 'ALTER TABLE  `'._DB_PREFIX.'user` ADD INDEX ( `customer_id` );';
             }
     
             $add_index=true;
             foreach($res as $r){
                 if(isset($r['Column_name']) && $r['Column_name'] == 'linked_parent_user_id'){
                     $add_index=false;
                 }
             }
             if($add_index){
                 $sql .= 'ALTER TABLE  `'._DB_PREFIX.'user` ADD INDEX ( `linked_parent_user_id` );';
             }*/
     $sql_check = "SHOW TABLES LIKE '" . _DB_PREFIX . "user_customer_rel'";
     $res = qa1($sql_check);
     if (!$res || !count($res)) {
         // create our new table.
         $sql .= 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX . 'user_customer_rel` (
         `user_id` int(11) NOT NULL,
         `customer_id` int(11) NOT NULL,
         `primary` INT NOT NULL DEFAULT  \'0\',
         PRIMARY KEY (`user_id`,`customer_id`)
         ) ENGINE=InnoDB DEFAULT CHARSET=utf8;';
     } else {
         // check primary exists
         $fields = get_fields('user_customer_rel');
         if (!isset($fields['primary'])) {
             $sql .= 'ALTER TABLE  `' . _DB_PREFIX . 'user_customer_rel` ADD  `primary` INT NOT NULL DEFAULT  \'0\'';
         }
     }
     return $sql;
 }
Example #12
0
 public function get_unread_count($search = array())
 {
     if (!module_security::is_logged_in()) {
         return 0;
     }
     $sql = "SELECT count(*) AS `unread` FROM `" . _DB_PREFIX . "social_facebook_message` m ";
     $sql .= " WHERE 1 ";
     $sql .= " AND m.social_facebook_message_id NOT IN (SELECT mr.social_facebook_message_id FROM `" . _DB_PREFIX . "social_facebook_message_read` mr WHERE mr.user_id = '" . (int) module_security::get_loggedin_id() . "' AND mr.social_facebook_message_id = m.social_facebook_message_id)";
     $sql .= " AND m.`status` = " . _SOCIAL_MESSAGE_STATUS_UNANSWERED;
     if (isset($search['social_facebook_page_id']) && $search['social_facebook_page_id'] !== false) {
         $sql .= " AND m.`social_facebook_page_id` = " . (int) $search['social_facebook_page_id'];
     }
     if (isset($search['social_facebook_id']) && $search['social_facebook_id'] !== false) {
         $sql .= " AND m.`social_facebook_id` = " . (int) $search['social_facebook_id'];
     }
     $res = qa1($sql);
     return $res ? $res['unread'] : 0;
 }
Example #13
0
 public static function email_blacklisted($email)
 {
     $email = trim(strtolower($email));
     if (!$email) {
         return true;
     }
     $sql = "SELECT * FROM `" . _DB_PREFIX . "newsletter_blacklist` b";
     $sql .= " WHERE b.email LIKE '" . mysql_real_escape_string($email) . "'";
     return qa1($sql);
 }
Example #14
0
 public static function db_table_exists($name, $force = false)
 {
     if (defined('_UCM_INSTALLED') && !_UCM_INSTALLED) {
         return false;
     }
     if ($force) {
         if (isset(self::$_dbt_exists[$name]) && self::$_dbt_exists[$name]) {
             return true;
         }
         $sql = "SHOW TABLES LIKE '" . _DB_PREFIX . $name . "'";
         $res = qa1($sql);
         if ($res != false && count($res)) {
             self::$_dbt_exists[$name] = true;
             return true;
         } else {
             self::$_dbt_exists[$name] = false;
             return false;
         }
     }
     if (count(self::$_dbt_exists)) {
         // we have queried db already.
         return isset(self::$_dbt_exists[$name]) && self::$_dbt_exists[$name];
     }
     // query all db tables first time to speed things up.
     $sql = "SHOW TABLES";
     $all = qa($sql);
     foreach ($all as $a) {
         $table_name = current($a);
         if ($table_name) {
             self::$_dbt_exists[str_replace(_DB_PREFIX, '', $table_name)] = true;
         }
     }
     if (isset(self::$_dbt_exists[$name])) {
         return self::$_dbt_exists[$name];
     }
     return false;
 }
Example #15
0
 public static function get_finance_recurring_items($hook, $search)
 {
     /**
      * next_due_date
      * url
      * type (i or e)
      * amount
      * currency_id
      * days
      * months
      * years
      * last_transaction_finance_id
      * account_name
      * categories
      * finance_recurring_id
      */
     // find any unpaid invoices.
     $invoices = self::get_invoices(array('date_paid' => '0000-00-00'));
     $return = array();
     foreach ($invoices as $invoice) {
         // filter out invoices that haven't been sent yet? probably should...
         //$invoice = self::get_invoice($invoice['invoice_id']);
         if (isset($invoice['date_cancel']) && $invoice['date_cancel'] != '0000-00-00') {
             continue;
         }
         // check if this invoice is part of a subscription, put in some additional info for this subscriptions
         // 'recurring_text'
         if ($invoice['member_id']) {
             $member_name = module_member::link_open($invoice['member_id'], true);
         } else {
             if ($invoice['customer_id']) {
                 $member_name = module_customer::link_open($invoice['customer_id'], true);
             } else {
                 $member_name = _l('N/A');
             }
         }
         $recurring_text = _l('Payment from %s', $member_name);
         if (class_exists('module_subscription', false) && isset($invoice['invoice_subscription_ids'])) {
             $sql = "SELECT sh.*, s.name FROM `" . _DB_PREFIX . "subscription_history` sh LEFT JOIN `" . _DB_PREFIX . "subscription` s USING (subscription_id) WHERE sh.invoice_id = " . (int) $invoice['invoice_id'] . "";
             $res = qa1($sql);
             if ($res) {
                 $subscription_name = module_subscription::link_open($res['subscription_id'], true, $res);
                 $recurring_text = _l('Payment from %s on subscription %s', $member_name, $subscription_name);
             }
         }
         if (!isset($invoice['c_total_amount_due'])) {
             $invoice = module_invoice::get_invoice($invoice['invoice_id']);
             $invoice['c_total_amount_due'] = $invoice['total_amount_due'];
         }
         $return[$invoice['invoice_id']] = array('next_due_date' => $invoice['date_due'] && $invoice['date_due'] != '0000-00-00' ? $invoice['date_due'] : $invoice['date_created'], 'url' => module_invoice::link_open($invoice['invoice_id'], true, $invoice), 'type' => 'i', 'amount' => $invoice['c_total_amount_due'], 'currency_id' => $invoice['currency_id'], 'days' => 0, 'months' => 0, 'years' => 0, 'last_transaction_finance_id' => 0, 'account_name' => '', 'categories' => '', 'finance_recurring_id' => 0, 'recurring_text' => $recurring_text);
     }
     // find any automatically renewing invoices.
     $invoices = self::get_invoices(array('renewing' => 1));
     foreach ($invoices as $invoice) {
         // filter out invoices that haven't been sent yet? probably should...
         //$invoice = self::get_invoice($invoice['invoice_id']);
         if (isset($invoice['date_cancel']) && $invoice['date_cancel'] != '0000-00-00') {
             continue;
         }
         // check if this invoice is part of a subscription, put in some additional info for this subscriptions
         // 'recurring_text'
         if ($invoice['member_id']) {
             $member_name = module_member::link_open($invoice['member_id'], true);
         } else {
             if ($invoice['customer_id']) {
                 $member_name = module_customer::link_open($invoice['customer_id'], true);
             } else {
                 $member_name = _l('N/A');
             }
         }
         if ($invoice['renew_auto']) {
             $recurring_text = _l('Automatically Renewing invoice for %s', $member_name);
         } else {
             $recurring_text = _l('Manually Renewing invoice for %s', $member_name);
         }
         if (!isset($invoice['c_total_amount'])) {
             $invoice = module_invoice::get_invoice($invoice['invoice_id']);
             $invoice['c_total_amount'] = $invoice['total_amount'];
         }
         $return[] = array('next_due_date' => date('Y-m-d', strtotime('+' . module_config::c('invoice_due_days', 30) . ' days', strtotime($invoice['date_renew']))), 'url' => module_invoice::link_open($invoice['invoice_id'], true, $invoice), 'type' => 'i', 'amount' => $invoice['c_total_amount'], 'currency_id' => $invoice['currency_id'], 'days' => 0, 'months' => 0, 'years' => 0, 'last_transaction_finance_id' => 0, 'account_name' => '', 'categories' => '', 'finance_recurring_id' => 0, 'recurring_text' => $recurring_text);
     }
     return $return;
 }
Example #16
0
 public static function read($session_id)
 {
     if (self::$destroyed) {
         return false;
     }
     self::$session_id = $session_id;
     if (!self::db_table_exists('session', true)) {
         return (string) @file_get_contents(_UCM_FOLDER . "/temp/sess_{$session_id}");
     }
     $sql = "SELECT `session_data` FROM `" . _DB_PREFIX . "session` WHERE `session_id` = '" . mysql_real_escape_string(self::$session_id) . "'";
     $res = qa1($sql);
     if ($res && isset($res['session_data'])) {
         $foo = base64_decode($res['session_data'], true);
         if (!$foo && preg_match('#^!([^!]*)!#', $res['session_data'], $matches)) {
             $res['session_data'] = preg_replace('#^' . preg_quote($matches[0], '#') . '#', '', $res['session_data']);
             if (function_exists('mb_detect_encoding') && mb_detect_encoding($res['session_data']) != $matches[1]) {
                 $res['session_data'] = iconv(mb_detect_encoding($res['session_data']), $matches[1], $res['session_data']);
             }
         } else {
             if ($foo) {
                 $res['session_data'] = $foo;
             }
         }
         self::$session_hash = md5($res['session_data']);
         return $res['session_data'];
     }
     return false;
 }
Example #17
0
 public static function c($key, $default = false, $options = array())
 {
     if (!defined('_UCM_INSTALLED')) {
         return $default;
     }
     if (isset(self::$_c[$key])) {
         return false;
     }
     // init_vars and save_config can sometimes cause a loop
     self::$_c[$key] = true;
     // check config table exists.
     if (!_UCM_INSTALLED) {
         if (_DB_USER && _DB_NAME) {
             db_connect();
             $sql = "SHOW TABLES LIKE '" . _DB_PREFIX . "config'";
             $res = qa1($sql);
         } else {
             $res = array();
         }
         if ($res != false && count($res)) {
             // config table exists, we're right to query
         } else {
             unset(self::$_c[$key]);
             return $default;
         }
     }
     // special keys, we only load once.
     switch ($key) {
         case 'sessions_in_database':
         case 'database_utf8':
             $sql = "SELECT `key`,`val` FROM `" . _DB_PREFIX . "config` WHERE `key` = '" . mysql_real_escape_string($key) . "'";
             $res = qa1($sql);
             if ($res && $res['key'] == $key) {
                 return $res['val'];
             } else {
                 if ($default !== false) {
                     self::save_config($key, $default);
                 }
             }
             break;
         default:
             // load all vars if needed.
             self::_init_vars();
     }
     if (!isset(self::$config_vars[$key]) && $default !== false) {
         self::save_config($key, $default);
         /*$sql = "INSERT INTO `"._DB_PREFIX."config` SET `key` = '".mysql_real_escape_string($key)."', `val` = '".mysql_real_escape_string($default)."'";
           query($sql);
           self::$config_vars[$key] = $default;*/
     }
     unset(self::$_c[$key]);
     return isset(self::$config_vars[$key]) ? self::$config_vars[$key] : false;
 }
Example #18
0
 public static function get_subscription($subscription_id)
 {
     $subscription_id = (int) $subscription_id;
     $subscription = false;
     if ($subscription_id > 0) {
         $sql = "SELECT s.* ";
         // COUNT(sm.subscription_id) AS member_count, COUNT(sc.subscription_id) AS customer_count ";
         $sql .= ", (SELECT COUNT(so1.subscription_id) FROM `" . _DB_PREFIX . "subscription_owner` so1 WHERE s.subscription_id = so1.subscription_id AND so1.owner_table = 'member' AND (so1.`deleted` = 0 OR so1.`deleted` IS NULL)) AS member_count";
         $sql .= ", (SELECT COUNT(so2.subscription_id) FROM `" . _DB_PREFIX . "subscription_owner` so2 WHERE s.subscription_id = so2.subscription_id AND so2.owner_table = 'customer' AND (so2.`deleted` = 0 OR so2.`deleted` IS NULL)) AS customer_count";
         $sql .= ", (SELECT COUNT(so3.subscription_id) FROM `" . _DB_PREFIX . "subscription_owner` so3 WHERE s.subscription_id = so3.subscription_id AND so3.owner_table = 'website' AND (so3.`deleted` = 0 OR so3.`deleted` IS NULL)) AS website_count";
         $sql .= " FROM `" . _DB_PREFIX . "subscription` s ";
         //            $sql .= " LEFT JOIN `"._DB_PREFIX."subscription_member` sm ON s.subscription_id = sm.subscription_id";
         //            $sql .= " LEFT JOIN `"._DB_PREFIX."subscription_customer` sc ON s.subscription_id = sc.subscription_id";
         $sql .= " WHERE s.subscription_id = " . (int) $subscription_id . "";
         //            $sql .=  " AND (sm.`deleted` = 0 OR sm.`deleted` IS NULL)";
         //            $sql .=  " AND (sc.`deleted` = 0 OR sc.`deleted` IS NULL)";
         $sql .= " GROUP BY s.subscription_id";
         $subscription = qa1($sql);
         $subscription['settings'] = isset($subscription['settings']) ? @json_decode($subscription['settings'], true) : array();
         if (!is_array($subscription['settings'])) {
             $subscription['settings'] = array();
         }
     }
     if (!$subscription) {
         $subscription = array('subscription_id' => '0', 'name' => '', 'days' => '', 'months' => '', 'years' => '', 'amount' => '', 'currency_id' => '', 'member_count' => 0, 'customer_count' => 0, 'website_count' => 0, 'settings' => array());
     }
     return $subscription;
 }
 // render the newsletter and display it on screen with nothing else.
 $content = module_newsletter::render($newsletter_id, $send_id, false, 'preview');
 // do the link click overview here:
 ob_end_clean();
 // grab all the links for this send
 $send_links = get_multiple('newsletter_link', array('send_id' => $send_id));
 $links_to_process = array();
 $old_links_by_url = array();
 foreach ($send_links as $send_link) {
     // we have to do this because the link processing part puts a unique member id into these unsubscribe/view online links.
     $parsed_url = preg_replace('#\\&nm=\\d+#', '&nm=', $send_link['link_url']);
     $parsed_url = preg_replace('#\\&hash=\\w+#', '&nm=', $parsed_url);
     // how many opens did this one have?
     $sql = "SELECT COUNT(*) AS `open_count` FROM `" . _DB_PREFIX . "newsletter_link_open` no ";
     $sql .= " WHERE no.send_id = " . (int) $send_id . " AND no.link_id = " . (int) $send_link['link_id'];
     $res = qa1($sql);
     if (!isset($old_links_by_url[$parsed_url])) {
         $old_links_by_url[$parsed_url] = array();
     }
     $links_to_process[$send_link['link_id']] = (int) $res['open_count'];
     $old_links_by_url[$parsed_url][$send_link['link_id']] = (int) $res['open_count'];
 }
 // this code is copied from newsletter::render
 $page_index = 1;
 foreach (array("href") as $type) {
     $parts = preg_split('/(<a[^>]+' . $type . '=["\'][^"\']+["\'])/', $content, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
     $content = '';
     foreach ($parts as $part_id => $content) {
         preg_match_all('/<a[^>]+' . $type . '=(["\'])([^"\']+)\\1/', $content, $links);
         if (is_array($links[2])) {
             foreach ($links[2] as $link_match_id => $l) {
Example #20
0
 public function is_email_limit_ok()
 {
     $limit_ok = true;
     switch (module_config::c('email_limit_period', 'day')) {
         case 'day':
             $start_time = strtotime("-24 hours");
             break;
         case 'hour':
             $start_time = strtotime("-1 hour");
             break;
         case 'minute':
             $start_time = time() - 60;
             break;
         default:
             $start_time = 0;
     }
     $send_limit = (int) module_config::c('email_limit_amount', 0);
     if ($start_time > 0 && $send_limit > 0) {
         // found a limit, see if it's broken
         $sql = "SELECT COUNT(email_id) AS send_count FROM `" . _DB_PREFIX . "email` WHERE sent_time > '{$start_time}'";
         $res = qa1($sql);
         if ($res && $res['send_count']) {
             // newsletters have been sent out - is it over the limit?
             if ($res['send_count'] >= $send_limit) {
                 $limit_ok = false;
             }
         }
     }
     return $limit_ok;
 }