/** * This is not the best example to follow * Please see the category plugin for a better example */ public function post() { require_once JPATH_SITE . '/components/com_acctexp/acctexp.class.php'; $db =& JFactory::getDBO(); $app = JFactory::getApplication(); $userid = JRequest::getInt('user_id', 0); $planid = JRequest::getInt('plan_id', 0); //$new_expiry = JRequest::getString('date',0); $obj = new stdClass(); //validate plan $plans = SubscriptionPlanHandler::getPlanList(); $muser = metaUserDB::getIDbyUserid($userid); //$pplan = metaUserDB::getPreviousPlan($muser); //$uplan = metaUserDB::getUsedPlans($muser); //print_r($new_expiry);die; if (!$userid) { $obj->success = 0; $obj->code = 21; $obj->message = "invalid user id"; } elseif (!$plans[array_search($planid, $plans)]) { $obj->success = 0; $obj->code = 22; $obj->message = "invalid plan id"; } else { $plan = new SubscriptionPlan($db); $plan->load($planid); //print_r($plan->params['full_period']);die; //check user is metauser /*if ( is_a( $user, 'metaUser' ) ) { $metaUser = $user; } elseif( is_a( $user, 'Subscription' ) ) { $metaUser = new metaUser( $user->userid ); $metaUser->focusSubscription = $user; }*/ $metaUser = new metaUser($userid); $renew = $metaUser->is_renewing(); //$metaUser->focusSubscription->lifetime; $metaUser->focusSubscription->plan = $planid; $metaUser->focusSubscription->status = 'Active'; $metaUser->temporaryRFIX(); //$metaUser->focusSubscription->lifetime = 1; //set expiration $now = (int) gmdate('U'); //$current = strtotime($new_expiry); //$metaUser->focusSubscription->expiration = $new_expiry; //$metaUser->objSubscription->expiration = $new_expiry; $reply = $metaUser->focusSubscription->storeload(); if ($reply && $planid) { $history = new logHistory($db); $obj->success = 1; $obj->message = "User added to plan"; } } $this->plugin->setResponse($obj); }
/** * This is not the best example to follow * Please see the category plugin for a better example */ public function post() { require_once JPATH_SITE . '/components/com_acctexp/acctexp.class.php'; $db =& JFactory::getDBO(); $app = JFactory::getApplication(); $userid = JRequest::getInt('user_id', 0); $planid = JRequest::getInt('plan_id', 0); $new_expiry = JRequest::getString('date', 0); //convert date in format $new_expiry = date("Y-m-d h:i:s", strtotime($new_expiry)); $obj = new stdClass(); //validate plan $plans = SubscriptionPlanHandler::getPlanList(); $muser = metaUserDB::getIDbyUserid($userid); $plnuser = SubscriptionPlanHandler::getPlanUserlist($planid); if (!$userid) { $obj->success = 0; $obj->code = 21; $obj->message = "invalid user id"; } elseif (!$plans[array_search($planid, $plans)]) { $obj->success = 0; $obj->code = 22; $obj->message = "invalid plan id"; } elseif ($userid == $plnuser[array_search($userid, $plnuser)]) { $plan = new SubscriptionPlan($db); $plan->load($planid); $metaUser = new metaUser($userid); $renew = $metaUser->is_renewing(); $lifetime = $metaUser->focusSubscription->lifetime; $metaUser->focusSubscription->plan = $planid; $metaUser->focusSubscription->status = 'Active'; $metaUser->temporaryRFIX(); $metaUser->focusSubscription->lifetime = 0; //set expiration //$now = (int) gmdate('U'); $metaUser->focusSubscription->expiration = $new_expiry; //$metaUser->objSubscription->expiration = $new_expiry; $reply = $metaUser->focusSubscription->storeload(); if ($reply && $planid) { $obj->success = 1; $obj->message = "Expiry updated"; } } else { $obj->success = 0; $obj->code = 31; $obj->message = "Plan not assigned to user"; } $this->plugin->setResponse($obj); }
public function Settings() { $db = JFactory::getDBO(); $settings = array(); if (!empty($_POST['type']) && !empty($_POST['id']) && empty($_POST['edit'])) { $db = JFactory::getDBO(); $settings['edit'] = array('hidden', 1); $settings['type'] = array('hidden', $_POST['type']); $fixed = array(); switch ($_POST['type']) { case 'metauser': $fixed = array('userid'); $object = new metaUserDB(); $s = AECToolbox::searchUser($_POST['id']); if (!empty($s)) { $_POST['id'] = $object->getIDbyUserid($s[0]); } else { $_POST['id'] = $object->getIDbyUserid((int) $_POST['id']); } break; case 'processor': if (!is_numeric($_POST['id'])) { $query = 'SELECT `id`' . ' FROM #__acctexp_config_processors' . ' WHERE `name` = \'' . (int) $_POST['id'] . '\''; $db->setQuery($query); $_POST['id'] = $db->loadResult(); } $object = new processor(); break; case 'invoice': if (!is_numeric($_POST['id'])) { $_POST['id'] = aecInvoiceHelper::InvoiceIDfromNumber($_POST['id']); } $object = new Invoice(); break; } $object->load($_POST['id']); $vars = get_object_vars($object); $encoded = $object->declareParamFields(); foreach ($vars as $k => $v) { if (is_null($k)) { $k = ""; } if ($k == 'id') { $settings['id'] = array('hidden', $v); } elseif (in_array($k, $fixed)) { $settings[$k] = array('p', $k, $k, $v); } elseif (in_array($k, $encoded)) { $v = jsoonHandler::encode($v); if ($v === "null") { $v = ""; } $settings[$k] = array('inputD', $k, $k, $v); } elseif (strpos($k, '_') !== 0) { $settings[$k] = array('inputD', $k, $k, $v); } } } else { $settings['type'] = array('list', 'Item Type', 'The type of Item you want to edit'); $settings['id'] = array('inputC', 'Item ID', 'Identification for your Item'); $types = array('metauser' => 'MetaUser Information', 'processor' => 'Payment Processor', 'invoice' => 'Invoice'); $typelist = array(); foreach ($types as $type => $typename) { $typelist[] = JHTML::_('select.option', $type, $typename); } $settings['lists']['type'] = JHTML::_('select.genericlist', $typelist, 'type', 'size="3"', 'value', 'text', array()); } return $settings; }