From c1d6f05ae85fbdf47d0de325ae331c5b09e469f7 Mon Sep 17 00:00:00 2001 From: Ashwin Date Date: Fri, 1 Feb 2013 21:07:50 +0530 Subject: [PATCH] Added AEC APIs as part of Gyre Consulting --- aec/aec.php | 23 ++++++ aec/aec.xml | 19 +++++ aec/aec/createuser.php | 148 +++++++++++++++++++++++++++++++++++++ aec/aec/planslist.php | 120 ++++++++++++++++++++++++++++++ aec/aec/setexpiration.php | 117 +++++++++++++++++++++++++++++ aec/aec/setusertoplan.php | 128 ++++++++++++++++++++++++++++++++ aec/aec/userlist.php | 151 ++++++++++++++++++++++++++++++++++++++ users/users/users.php | 2 +- 8 files changed, 707 insertions(+), 1 deletion(-) create mode 100755 aec/aec.php create mode 100755 aec/aec.xml create mode 100755 aec/aec/createuser.php create mode 100755 aec/aec/planslist.php create mode 100755 aec/aec/setexpiration.php create mode 100755 aec/aec/setusertoplan.php create mode 100755 aec/aec/userlist.php diff --git a/aec/aec.php b/aec/aec.php new file mode 100755 index 0000000..caebfd7 --- /dev/null +++ b/aec/aec.php @@ -0,0 +1,23 @@ + + + Api - aec + 1.0 + Jan 2013 + Tekdi + support@tekdi.com + http://www.tekdi.com + 2012 users + GNU General Public License v2 + API plugins of AEC components of the Joomla! + + + aec.php + aec/userlist.php + aec/createuser.php + aec + + diff --git a/aec/aec/createuser.php b/aec/aec/createuser.php new file mode 100755 index 0000000..9e4579b --- /dev/null +++ b/aec/aec/createuser.php @@ -0,0 +1,148 @@ +0,"id"=>16,"fieldname"=>"email","message"=>"Email cannot be blank"); + } elseif( false == $this->isValidEmail( $data['email'] ) ) { + $validated = false; + $error_messages[] = array("success"=>0,"id"=>16,"fieldname"=>"email","message"=>"Please set valid email id eg.(example@gmail.com). Check 'email' field in request"); + + } + if( $data['password']=="" ) + { + $validated = false; + $error_messages[] = array("success"=>0,"id"=>15,"fieldname"=>"password","message"=>"Password cannot be blank"); + } + + if( $data['name']=="" or $data['username']=="" ) + { + $validated = false; + $error_messages[] = array("success"=>0,"id"=>14,"fieldname"=>"name/username","message"=>"Name cannot be blank"); + } + + if( true == $validated) + { //to create new user for joomla + + global $message; + jimport('joomla.user.helper'); + $authorize = & JFactory::getACL(); + $user = clone(JFactory::getUser()); + $user->set('username', $data['username']); + $user->set('password', $data['password'] ); + $user->set('name', $data['name']); + $user->set('email', $data['email']); + + // password encryption + $salt = JUserHelper::genRandomPassword(32); + $crypt = JUserHelper::getCryptedPassword($user->password, $salt); + $user->password = "$crypt:$salt"; + + // user group/type + $user->set('id', ''); + $user->set('usertype', 'Registered'); + if(JVERSION >= '1.6.0') + { + $userConfig = JComponentHelper::getParams('com_users'); + // Default to Registered. + $defaultUserGroup = $userConfig->get('new_usertype', 2); + $user->set('groups', array($defaultUserGroup)); + } + else + $user->set('gid', $authorize->get_group_id( '', 'Registered', 'ARO' )); + + $date =& JFactory::getDate(); + $user->set('registerDate', $date->toMySQL()); + + // true on success, false otherwise + if(!$user->save()) + { + $message="not created because of ".$user->getError(); + return false; + } + else + { + $message="created of username-".$user->username." and send mail of details please check"; + + } + //$this->plugin->setResponse($user->id); + $userid = $user->id; + + //result message + $result = array('success'=>1,'user id '=>$userid,'username'=>$user->username,'message'=>$message); + $result =($userid) ? $result : $message; + + $this->plugin->setResponse($result); + + + } + else + { + + $this->plugin->setResponse($error_messages);//print_r($error_messages); die("validate mail2222"); + } + + + + } + + function isValidEmail( $email ) + { + $pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i"; + + if ( preg_match( $pattern, $email ) ) + { + return true; + } else { + return false; + } + } + +} diff --git a/aec/aec/planslist.php b/aec/aec/planslist.php new file mode 100755 index 0000000..7b845df --- /dev/null +++ b/aec/aec/planslist.php @@ -0,0 +1,120 @@ +100)?100:$limit; + + $t_plans = SubscriptionPlanHandler::getFullPlanList(); + $plans = SubscriptionPlanHandler::getFullPlanList($limitstart,$limit); + $data = array(); + $data["total"] = count($t_plans); + $sel_plan = array(); + foreach($plans as $k=>$val) + { + + //$val->group_id = ItemGroupHandler::getItemListItem($val); + unset($val->params); + unset($val->custom_params); + unset($val->restrictions); + unset($val->micro_integrations); + unset($val->lifetime); + unset($val->email_desc); + + if($active && $visible && $val->active == 1 && $val->visible == 1 ) + { + $sel_plan[$val->id] = $val; + } + elseif($active && $val->active == $active && $val->visible != 0 ) + { + + $sel_plan[$val->id] = $val; + } + elseif($visible && $val->visible == $visible && $val->active != 0) + { + + $sel_plan[$val->id] = $val; + } + elseif($visible ==0 && $active == 0 && $name == '' ) + { + $sel_plan[$val->id] = $val; + } + + } + //$match = preg_match($pattern, $val->name); + $name_arr = array(); + foreach($sel_plan as $k=>$v) + { + + if(preg_match($pattern, $v->name)) + { + + $name_arr[$v->id] = $v; + } + $sel_plan =$name_arr; + } + + + + $data['count']=count($sel_plan); + $data['users']=$sel_plan; + $this->plugin->setResponse($data); + + + } + + /** + * This is not the best example to follow + * Please see the category plugin for a better example + */ + public function post() + { + + $this->plugin->setResponse( "this is post data" ); + } + + public function put() + { + // Simply call post as K2 will just save an item with an id + /*$this->post(); + + $response = $this->plugin->get( 'response' ); + if ( isset( $response->success ) && $response->success ) { + JResponse::setHeader( 'status', 200, true ); + $response->code = 200; + $this->plugin->setResponse( $response ); + }*/ + } + + function qry() + { + $db = &JFactory::getDBO(); + $qry = "SELECT count(*) FROM #__acctexp_subscr AS a INNER JOIN #__users AS b ON a.userid = b.id WHERE ((a.status = 'Active' || a.status = 'Trial'))"; + $db->setQuery( $query ); + $total = $db->loadResult(); +} + +} diff --git a/aec/aec/setexpiration.php b/aec/aec/setexpiration.php new file mode 100755 index 0000000..e0101f7 --- /dev/null +++ b/aec/aec/setexpiration.php @@ -0,0 +1,117 @@ +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 put() + { + + } + + function qry() + { + /*$db = &JFactory::getDBO(); + $qry = "SELECT count(*) FROM #__acctexp_subscr AS a INNER JOIN #__users AS b ON a.userid = b.id WHERE ((a.status = 'Active' || a.status = 'Trial'))"; + $db->setQuery( $query ); + $total = $db->loadResult(); */ +} + +} diff --git a/aec/aec/setusertoplan.php b/aec/aec/setusertoplan.php new file mode 100755 index 0000000..8938f50 --- /dev/null +++ b/aec/aec/setusertoplan.php @@ -0,0 +1,128 @@ +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); + + } + + public function put() + { + // Simply call post as K2 will just save an item with an id + /*$this->post(); + + $response = $this->plugin->get( 'response' ); + if ( isset( $response->success ) && $response->success ) { + JResponse::setHeader( 'status', 200, true ); + $response->code = 200; + $this->plugin->setResponse( $response ); + }*/ + } + + function qry() + { + $db = &JFactory::getDBO(); + $qry = "SELECT count(*) FROM #__acctexp_subscr AS a INNER JOIN #__users AS b ON a.userid = b.id WHERE ((a.status = 'Active' || a.status = 'Trial'))"; + $db->setQuery( $query ); + $total = $db->loadResult(); +} + +} diff --git a/aec/aec/userlist.php b/aec/aec/userlist.php new file mode 100755 index 0000000..6b5c8e2 --- /dev/null +++ b/aec/aec/userlist.php @@ -0,0 +1,151 @@ +setQuery( $query ); + $total = $db->loadResult(); + + $query = "SELECT a.*, b.name, b.username, b.email, c.name AS plan_name FROM #__acctexp_subscr AS a INNER JOIN #__users AS b ON a.userid = b.id LEFT JOIN #__acctexp_plans AS c ON a.plan = c.id "; + + $where = array(); + + + if ( $userid) + { + + $where[] = "b.id ={$userid}"; + } + if ($name) + { + + $where[] = " b.name LIKE '%{$name}%' "; + } + if ($username !='' ) + { + $where[] = " b.username LIKE '%{$username}%' "; + } + if ($email) + { + $where[] = "b.email = '{$email}'"; + } + + if($plan_status != '') + { + $where[] = "a.status = '{$plan_status}'"; + } + + $where = count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' ; + $query .= $where; + $query .= " ORDER BY {$ordering} {$orderingdir} LIMIT {$limitstart},{$limit}"; +//die("in userlist api"); + $db->setQuery( $query ); + $users = $db->loadObjectList(); + $pln = new stdClass; + foreach($users as $key=>$val) + { + $pln->plan = $val->plan; + $pln->id = $val->id; + $pln->type = $val->type; + $pln->status = $val->status; + $pln->signup_date = $val->signup_date; + $pln->expiration = $val->expiration; + + unset($val->params); + unset($val->primary); + unset($val->plan_name); + unset($val->recurring); + unset($val->lifetime); + unset($val->customparams); + unset($val->lastpay_date); + unset($val->eot_date); + unset($val->eot_cause); + unset($val->plan); + unset($val->id); + unset($val->type); + unset($val->status); + unset($val->signup_date); + unset($val->expiration); + unset($val->cancel_date); + $val->id = $val->userid; + $val->plan = $pln; + + unset($val->userid); + + $users[$key] = $val; + } + + $data = array('total'=>$total,'count'=>count($users),'data'=>$users); + + $this->plugin->setResponse($data); + + + } + + /** + * This is not the best example to follow + * Please see the category plugin for a better example + */ + public function post() + { + + $this->plugin->setResponse( "this is post data" ); + } + + public function put() + { + // Simply call post as K2 will just save an item with an id + /*$this->post(); + + $response = $this->plugin->get( 'response' ); + if ( isset( $response->success ) && $response->success ) { + JResponse::setHeader( 'status', 200, true ); + $response->code = 200; + $this->plugin->setResponse( $response ); + }*/ + } + + /*function qry() + { + $db = &JFactory::getDBO(); + $qry = "SELECT count(*) FROM #__acctexp_subscr AS a INNER JOIN #__users AS b ON a.userid = b.id WHERE ((a.status = 'Active' || a.status = 'Trial'))"; + $db->setQuery( $query ); + $total = $db->loadResult(); +}*/ + +} diff --git a/users/users/users.php b/users/users/users.php index 9b102cc..d945355 100755 --- a/users/users/users.php +++ b/users/users/users.php @@ -139,7 +139,7 @@ public function post() else { - $this->plugin->setResponse($error_messages);//print_r($error_messages); die("validate mail2222"); + $this->plugin->setResponse($error_messages); }