Пример #1
0
 public function import($options = array())
 {
     $db = JFactory::getDBO();
     $stdfields = array('id', 'name', 'username', 'email', 'password', 'plan_id', 'invoice_number', 'expiration');
     foreach ($this->rows as $k => $row) {
         // Skip first line, if desired
         if ($k === 0 && !empty($options['skip_first'])) {
             continue;
         }
         $userid = null;
         $user = $this->convertRow($row);
         if (empty($user['username']) && empty($user['id'])) {
             continue;
         }
         if (!empty($user['id'])) {
             $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `id` = \'' . $user['id'] . '\'';
             $db->setQuery($query);
             $userid = $db->loadResult();
         }
         if (empty($userid)) {
             $query = 'SELECT `id`' . ' FROM #__users' . ' WHERE `username` = \'' . $user['username'] . '\'';
             $db->setQuery($query);
             $userid = $db->loadResult();
         }
         if (!$userid) {
             // We cannot find any user by this id or name, create one
             if (!empty($user['email']) && !empty($user['username'])) {
                 if (empty($user['password'])) {
                     $user['password'] = AECToolbox::randomstring(8, true);
                 }
                 if (empty($user['name'])) {
                     $user['name'] = $user['username'];
                 }
                 if (!empty($user['password'])) {
                     $user['password2'] = $user['password'];
                 }
                 $fields = $user;
                 $excludefields = array('plan_id', 'invoice_number', 'expiration');
                 foreach ($excludefields as $field) {
                     if (isset($fields[$field])) {
                         unset($fields[$field]);
                     }
                 }
                 $userid = $this->createUser($fields);
             } else {
                 continue;
             }
         }
         if (empty($userid)) {
             $this->errors++;
         }
         $metaUser = new metaUser($userid);
         $custom_params = array();
         foreach ($user as $i => $v) {
             if (!in_array($i, $stdfields)) {
                 $custom_params[$i] = $v;
             }
         }
         if (!empty($custom_params)) {
             $metaUser->meta->addCustomParams($custom_params);
             $metaUser->meta->storeload();
         }
         if (!empty($user['plan_id'])) {
             $pid = $user['plan_id'];
         } else {
             $pid = $this->options['assign_plan'];
         }
         $subscr_action = false;
         if (!empty($pid)) {
             $plan = new SubscriptionPlan();
             $plan->load($pid);
             $metaUser->establishFocus($plan, 'none', true);
             $metaUser->focusSubscription->applyUsage($pid, 'none', 1);
             $subscr_action = true;
         }
         if (!empty($user['expiration']) && !empty($metaUser->focusSubscription->id)) {
             $metaUser->focusSubscription->expiration = date('Y-m-d H:i:s', strtotime($user['expiration']));
             if ($metaUser->focusSubscription->status == 'Trial') {
                 $metaUser->focusSubscription->status = 'Trial';
             } else {
                 $metaUser->focusSubscription->status = 'Active';
             }
             $metaUser->focusSubscription->lifetime = 0;
             $metaUser->focusSubscription->storeload();
             $subscr_action = true;
         }
         if (!empty($user['invoice_number']) && !empty($pid)) {
             // Create Invoice
             $invoice = new Invoice();
             $invoice->create($userid, $pid, 'none', $user['invoice_number']);
             if ($subscr_action) {
                 $invoice->subscr_id = $metaUser->focusSubscription->id;
             }
             $invoice->setTransactionDate();
         }
     }
 }
Пример #2
0
 public function save()
 {
     $user = JFactory::getUser();
     global $aecConfig;
     $general_settings = AECToolbox::cleanPOST($_POST, false);
     if (!empty($general_settings['apiapplist'])) {
         $list = explode("\n", $general_settings['apiapplist']);
         $array = array();
         foreach ($list as $item) {
             $li = explode("=", $item, 2);
             $k = $li[0];
             if (!empty($k)) {
                 if (!empty($li[1])) {
                     $v = $li[1];
                 } else {
                     $v = AECToolbox::randomstring(32, true, true);
                 }
                 $array[$k] = $v;
             }
         }
         $general_settings['apiapplist'] = $array;
     } else {
         $general_settings['apiapplist'] = array();
     }
     $diff = $aecConfig->diffParams($general_settings, 'settings');
     if (is_array($diff)) {
         $newdiff = array();
         foreach ($diff as $value => $change) {
             $newdiff[] = $value . '(' . implode(' -> ', $change) . ')';
         }
         $difference = implode(',', $newdiff);
     } else {
         $difference = 'none';
     }
     if (defined('JPATH_MANIFESTS')) {
         if ($aecConfig->cfg['manageraccess'] !== $general_settings['manageraccess']) {
             if ($general_settings['manageraccess']) {
                 $set = '{"core.admin":{"7":1},"core.manage":{"6":1},"core.create":[],"core.delete":[],"core.edit":[],"core.edit.state":[]}';
             } else {
                 $set = '{}';
             }
             $query = 'UPDATE #__assets' . ' SET `rules` = \'' . xJ::escape($this->db, $set) . '\'' . ' WHERE `name` = \'com_acctexp\'';
             $this->db->setQuery($query);
             $this->db->query();
         }
     }
     $aecConfig->cfg = $general_settings;
     $aecConfig->saveSettings();
     $ip = AECToolbox::aecIP();
     $short = JText::_('AEC_LOG_SH_SETT_SAVED');
     $event = JText::_('AEC_LOG_LO_SETT_SAVED') . ' ' . $difference;
     $tags = 'settings,system';
     $params = array('userid' => $user->id, 'ip' => $ip['ip'], 'isp' => $ip['isp']);
     $eventlog = new eventLog();
     $eventlog->issue($short, $tags, $event, 2, $params);
     if (!empty($aecConfig->cfg['entry_plan'])) {
         $plan = new SubscriptionPlan();
         $plan->load($aecConfig->cfg['entry_plan']);
         $terms = $plan->getTerms();
         if (!$terms->checkFree()) {
             $short = "Settings Warning";
             $event = "You have selected a non-free plan as Entry Plan." . " Please keep in mind that this means that users" . " will be getting it for free when they log in" . " without having any membership";
             $tags = 'settings,system';
             $params = array('userid' => $user->id, 'ip' => $ip['ip'], 'isp' => $ip['isp']);
             $eventlog = new eventLog();
             $eventlog->issue($short, $tags, $event, 32, $params);
         }
     }
     $this->setMessage(JText::_('AEC_CONFIG_SAVED'));
 }
Пример #3
0
 public function executeCommand($command, $vars, $safe = false)
 {
     $result = '';
     switch ($command) {
         case 'rw_constant':
             if (isset($this->rewrite[$vars])) {
                 $result = $this->rewrite[$vars];
             }
             break;
         case 'data':
             if (empty($this->data)) {
                 return false;
             }
             $result = AECToolbox::getObjectProperty($this->data, $vars);
             break;
         case 'safedata':
             if (empty($this->data)) {
                 return false;
             }
             if (AECToolbox::getObjectProperty($this->data, $vars, true)) {
                 $result = AECToolbox::getObjectProperty($this->data, $vars);
             }
             break;
         case 'checkdata':
             if (empty($this->data)) {
                 return false;
             }
             $result = AECToolbox::getObjectProperty($this->data, $vars, true);
             break;
         case 'checkdata_notempty':
             if (empty($this->data)) {
                 return false;
             }
             $check = AECToolbox::getObjectProperty($this->data, $vars, true);
             if (AECToolbox::getObjectProperty($this->data, $vars, true)) {
                 $check = AECToolbox::getObjectProperty($this->data, $vars);
                 $result = !empty($check);
             }
             break;
         case 'metaUser':
             if (!is_object($this->data['metaUser'])) {
                 return false;
             }
             // We also support dot notation for the vars,
             // so explode if that is what the admin wants here
             if (!is_array($vars) && strpos($vars, '.') !== false) {
                 $temp = explode('.', $vars);
                 $vars = $temp;
             } elseif (!is_array($vars)) {
                 return false;
             }
             $result = $this->data['metaUser']->getProperty($vars);
             break;
         case 'invoice_count':
             if (!is_object($this->data['metaUser'])) {
                 return false;
             }
             return aecInvoiceHelper::InvoiceCountbyUserID($this->data['metaUser']->userid);
             break;
         case 'invoice_count_paid':
             if (!is_object($this->data['metaUser'])) {
                 return false;
             }
             return aecInvoiceHelper::PaidInvoiceCountbyUserID($this->data['metaUser']->userid);
             break;
         case 'invoice_count_unpaid':
             if (!is_object($this->data['metaUser'])) {
                 return false;
             }
             return aecInvoiceHelper::UnpaidInvoiceCountbyUserID($this->data['metaUser']->userid);
             break;
         case 'jtext':
             $result = JText::_($vars);
             break;
         case 'constant':
             if (defined($vars)) {
                 $result = constant($vars);
             } else {
                 $result = JText::_($vars);
             }
             break;
         case 'global':
             if (is_array($vars)) {
                 if (isset($vars[0]) && isset($vars[1])) {
                     $call = strtoupper($vars[0]);
                     $v = $vars[1];
                     $allowed = array('SERVER', 'GET', 'POST', 'FILES', 'COOKIE', 'SESSION', 'REQUEST', 'ENV');
                     if (in_array($call, $allowed)) {
                         switch ($call) {
                             case 'SERVER':
                                 if (isset($_SERVER[$v]) && !$safe) {
                                     $result = $_SERVER[$v];
                                 }
                                 break;
                             case 'GET':
                                 if (isset($_GET[$v])) {
                                     $result = $_GET[$v];
                                 }
                                 break;
                             case 'POST':
                                 if (isset($_POST[$v])) {
                                     $result = $_POST[$v];
                                 }
                                 break;
                             case 'FILES':
                                 if (isset($_FILES[$v]) && !$safe) {
                                     $result = $_FILES[$v];
                                 }
                                 break;
                             case 'COOKIE':
                                 if (isset($_COOKIE[$v])) {
                                     $result = $_COOKIE[$v];
                                 }
                                 break;
                             case 'SESSION':
                                 if (isset($_SESSION[$v])) {
                                     $result = $_SESSION[$v];
                                 }
                                 break;
                             case 'REQUEST':
                                 if (isset($_REQUEST[$v])) {
                                     $result = $_REQUEST[$v];
                                 }
                                 break;
                             case 'ENV':
                                 if (isset($_ENV[$v]) && !$safe) {
                                     $result = $_ENV[$v];
                                 }
                                 break;
                         }
                     }
                 }
             } else {
                 if (isset($GLOBALS[$vars])) {
                     $result = $GLOBALS[$vars];
                 }
             }
             break;
         case 'condition':
             if (empty($vars[0]) || !isset($vars[1])) {
                 if (isset($vars[2])) {
                     $result = $vars[2];
                 } else {
                     $result = '';
                 }
             } elseif (isset($vars[1])) {
                 $result = $vars[1];
             } else {
                 $result = '';
             }
             break;
         case 'hastext':
             $result = strpos($vars[0], $vars[1]) !== false ? 1 : 0;
             break;
         case 'uppercase':
             $result = strtoupper($vars);
             break;
         case 'lowercase':
             $result = strtoupper($vars);
             break;
         case 'concat':
             $result = implode($vars);
             break;
         case 'date':
             $result = date($vars[0], strtotime($vars[1]));
             break;
         case 'date_distance':
             $result = round($vars - (int) gmdate('U'));
             break;
         case 'date_distance_days':
             $result = round(($vars - (int) gmdate('U')) / 86400);
             break;
         case 'crop':
             if (isset($vars[2])) {
                 $result = substr($vars[0], (int) $vars[1], (int) $vars[2]);
             } else {
                 $result = substr($vars[0], (int) $vars[1]);
             }
             break;
         case 'pad':
             if (isset($vars[3])) {
                 $result = str_pad($vars[0], (int) $vars[1], $vars[2], JText::_("STR_PAD_" . strtoupper($vars[3])));
             } elseif (isset($vars[2])) {
                 $result = str_pad($vars[0], (int) $vars[1], $vars[2]);
             } else {
                 $result = str_pad($vars[0], (int) $vars[1]);
             }
             break;
         case 'chunk':
             $chunks = str_split($vars[0], (int) $vars[1]);
             if (isset($vars[2])) {
                 $result = implode($vars[2], $chunks);
             } else {
                 $result = implode(' ', $chunks);
             }
             break;
         case 'compare':
             if (isset($vars[2])) {
                 $result = AECToolbox::compare($vars[1], $vars[0], $vars[2]);
             } else {
                 $result = 0;
             }
             break;
         case 'math':
             if (isset($vars[2])) {
                 $result = AECToolbox::math($vars[1], (double) $vars[0], (double) $vars[2]);
             } else {
                 $result = 0;
             }
             break;
         case 'randomstring':
             $result = AECToolbox::randomstring((int) $vars);
             break;
         case 'randomstring_alphanum':
             $result = AECToolbox::randomstring((int) $vars, true);
             break;
         case 'randomstring_alphanum_large':
             $result = AECToolbox::randomstring((int) $vars, true, true);
             break;
         case 'php_function':
             if (!$safe) {
                 if (isset($vars[1])) {
                     $result = call_user_func_array($vars[0], $vars[1]);
                 } else {
                     $result = call_user_func_array($vars[0], array());
                 }
             }
             break;
         case 'php_method':
             if (!$safe) {
                 $callback = array($vars[0], $vars[1]);
                 if (isset($vars[2])) {
                     $result = call_user_func_array($callback, $vars[2]);
                 } else {
                     $result = call_user_func_array($callback, array());
                 }
             }
             break;
         default:
             $result = $command . ' is no command';
             break;
     }
     return $result;
 }