Skip to content

Commit c1d6f05

Browse files
author
Ashwin Date
committed
Added AEC APIs as part of Gyre Consulting
1 parent 6440786 commit c1d6f05

File tree

8 files changed

+707
-1
lines changed

8 files changed

+707
-1
lines changed

aec/aec.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* @package API
4+
* @version 1.5
5+
* @author Brian Edgerton
6+
* @link http://www.edgewebworks.com
7+
* @copyright Copyright (C) 2011 Edge Web Works, LLC. All rights reserved.
8+
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
9+
*/
10+
11+
defined('_JEXEC') or die( 'Restricted access' );
12+
13+
jimport('joomla.plugin.plugin');
14+
15+
class plgAPIAec extends ApiPlugin
16+
{
17+
public function __construct()
18+
{
19+
parent::__construct();
20+
21+
ApiResource::addIncludePath(dirname(__FILE__).'/aec');
22+
}
23+
}

aec/aec.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<install version="1.7" type="plugin" group="api" method="upgrade">
3+
<name>Api - aec</name>
4+
<version>1.0</version>
5+
<creationDate>Jan 2013</creationDate>
6+
<author>Tekdi</author>
7+
<authorEmail>[email protected]</authorEmail>
8+
<authorUrl>http://www.tekdi.com</authorUrl>
9+
<copyright>2012 users</copyright>
10+
<license>GNU General Public License v2</license>
11+
<description>API plugins of AEC components of the Joomla! </description>
12+
13+
<files>
14+
<filename plugin="aec">aec.php</filename>
15+
<filename >aec/userlist.php</filename>
16+
<filename >aec/createuser.php</filename>
17+
<folder>aec</folder>
18+
</files>
19+
</install>

aec/aec/createuser.php

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
/**
3+
* @package API
4+
* @version 1.5
5+
* @author Brian Edgerton
6+
* @link http://www.edgewebworks.com
7+
* @copyright Copyright (C) 2011 Edge Web Works, LLC. All rights reserved.
8+
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
9+
*/
10+
11+
defined('_JEXEC') or die( 'Restricted access' );
12+
13+
jimport('joomla.plugin.plugin');
14+
jimport('joomla.html.html');
15+
jimport('joomla.user.helper');
16+
jimport( 'joomla.application.component.helper' );
17+
jimport( 'joomla.application.component.model' );
18+
jimport( 'joomla.database.table.user' );
19+
20+
require_once( JPATH_SITE .DS.'libraries'.DS.'joomla'.DS.'filesystem'.DS.'folder.php');
21+
22+
/*if(JFolder::exists(JPATH_BASE.DS.'components'.DS.'com_xipt'))
23+
{
24+
require_once( JPATH_SITE .DS.'components'.DS.'com_xipt'.DS.'api.xipt.php');
25+
}*/
26+
27+
class AecApiResourceCreateuser extends ApiResource
28+
{
29+
30+
public function post()
31+
{
32+
33+
$error_messages = array();
34+
$fieldname = array();
35+
$response = NULL;
36+
$validated = true;
37+
$userid = NULL;
38+
$data = JRequest::get('post');
39+
40+
//for rest api only
41+
unset($data['format']);
42+
unset($data['resource']);
43+
unset($data['app']);
44+
unset($data['key']);
45+
//
46+
//$userid = $data['userid'];
47+
//$fields = $data['field'];
48+
//print_r($_POST); die;
49+
//chk data
50+
if($data['email']=="" )
51+
{
52+
$validated = false;
53+
$error_messages[] = array("success"=>0,"id"=>16,"fieldname"=>"email","message"=>"Email cannot be blank");
54+
} elseif( false == $this->isValidEmail( $data['email'] ) ) {
55+
$validated = false;
56+
$error_messages[] = array("success"=>0,"id"=>16,"fieldname"=>"email","message"=>"Please set valid email id eg.([email protected]). Check 'email' field in request");
57+
58+
}
59+
if( $data['password']=="" )
60+
{
61+
$validated = false;
62+
$error_messages[] = array("success"=>0,"id"=>15,"fieldname"=>"password","message"=>"Password cannot be blank");
63+
}
64+
65+
if( $data['name']=="" or $data['username']=="" )
66+
{
67+
$validated = false;
68+
$error_messages[] = array("success"=>0,"id"=>14,"fieldname"=>"name/username","message"=>"Name cannot be blank");
69+
}
70+
71+
if( true == $validated)
72+
{ //to create new user for joomla
73+
74+
global $message;
75+
jimport('joomla.user.helper');
76+
$authorize = & JFactory::getACL();
77+
$user = clone(JFactory::getUser());
78+
$user->set('username', $data['username']);
79+
$user->set('password', $data['password'] );
80+
$user->set('name', $data['name']);
81+
$user->set('email', $data['email']);
82+
83+
// password encryption
84+
$salt = JUserHelper::genRandomPassword(32);
85+
$crypt = JUserHelper::getCryptedPassword($user->password, $salt);
86+
$user->password = "$crypt:$salt";
87+
88+
// user group/type
89+
$user->set('id', '');
90+
$user->set('usertype', 'Registered');
91+
if(JVERSION >= '1.6.0')
92+
{
93+
$userConfig = JComponentHelper::getParams('com_users');
94+
// Default to Registered.
95+
$defaultUserGroup = $userConfig->get('new_usertype', 2);
96+
$user->set('groups', array($defaultUserGroup));
97+
}
98+
else
99+
$user->set('gid', $authorize->get_group_id( '', 'Registered', 'ARO' ));
100+
101+
$date =& JFactory::getDate();
102+
$user->set('registerDate', $date->toMySQL());
103+
104+
// true on success, false otherwise
105+
if(!$user->save())
106+
{
107+
$message="not created because of ".$user->getError();
108+
return false;
109+
}
110+
else
111+
{
112+
$message="created of username-".$user->username." and send mail of details please check";
113+
114+
}
115+
//$this->plugin->setResponse($user->id);
116+
$userid = $user->id;
117+
118+
//result message
119+
$result = array('success'=>1,'user id '=>$userid,'username'=>$user->username,'message'=>$message);
120+
$result =($userid) ? $result : $message;
121+
122+
$this->plugin->setResponse($result);
123+
124+
125+
}
126+
else
127+
{
128+
129+
$this->plugin->setResponse($error_messages);//print_r($error_messages); die("validate mail2222");
130+
}
131+
132+
133+
134+
}
135+
136+
function isValidEmail( $email )
137+
{
138+
$pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i";
139+
140+
if ( preg_match( $pattern, $email ) )
141+
{
142+
return true;
143+
} else {
144+
return false;
145+
}
146+
}
147+
148+
}

aec/aec/planslist.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* @package K2 API plugin
4+
* @version 1.0
5+
* @author Rafael Corral
6+
* @link http://www.rafaelcorral.com
7+
* @copyright Copyright (C) 2011 Rafael Corral. All rights reserved.
8+
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
9+
*/
10+
11+
defined('_JEXEC') or die;
12+
13+
jimport('joomla.plugin.plugin');
14+
//function in file - /var/www/mppronline/administrator/components/com_acctexp/admin.acctexp.php
15+
16+
17+
class AecApiResourcePlanslist extends ApiResource
18+
{
19+
public function get()
20+
{
21+
require_once JPATH_SITE .'/components/com_acctexp/acctexp.class.php';
22+
$limitstart = JRequest::getInt('limitstart',0);
23+
$limit = JRequest::getInt('limit',20);
24+
$active = JRequest::getInt('active',0);
25+
$visible = JRequest::getInt('visible',0);
26+
$name = JRequest::getVar('name','');
27+
$pattern = '/' . preg_quote($name, '/') . '/';
28+
29+
$limit = ($limit>100)?100:$limit;
30+
31+
$t_plans = SubscriptionPlanHandler::getFullPlanList();
32+
$plans = SubscriptionPlanHandler::getFullPlanList($limitstart,$limit);
33+
$data = array();
34+
$data["total"] = count($t_plans);
35+
$sel_plan = array();
36+
foreach($plans as $k=>$val)
37+
{
38+
39+
//$val->group_id = ItemGroupHandler::getItemListItem($val);
40+
unset($val->params);
41+
unset($val->custom_params);
42+
unset($val->restrictions);
43+
unset($val->micro_integrations);
44+
unset($val->lifetime);
45+
unset($val->email_desc);
46+
47+
if($active && $visible && $val->active == 1 && $val->visible == 1 )
48+
{
49+
$sel_plan[$val->id] = $val;
50+
}
51+
elseif($active && $val->active == $active && $val->visible != 0 )
52+
{
53+
54+
$sel_plan[$val->id] = $val;
55+
}
56+
elseif($visible && $val->visible == $visible && $val->active != 0)
57+
{
58+
59+
$sel_plan[$val->id] = $val;
60+
}
61+
elseif($visible ==0 && $active == 0 && $name == '' )
62+
{
63+
$sel_plan[$val->id] = $val;
64+
}
65+
66+
}
67+
//$match = preg_match($pattern, $val->name);
68+
$name_arr = array();
69+
foreach($sel_plan as $k=>$v)
70+
{
71+
72+
if(preg_match($pattern, $v->name))
73+
{
74+
75+
$name_arr[$v->id] = $v;
76+
}
77+
$sel_plan =$name_arr;
78+
}
79+
80+
81+
82+
$data['count']=count($sel_plan);
83+
$data['users']=$sel_plan;
84+
$this->plugin->setResponse($data);
85+
86+
87+
}
88+
89+
/**
90+
* This is not the best example to follow
91+
* Please see the category plugin for a better example
92+
*/
93+
public function post()
94+
{
95+
96+
$this->plugin->setResponse( "this is post data" );
97+
}
98+
99+
public function put()
100+
{
101+
// Simply call post as K2 will just save an item with an id
102+
/*$this->post();
103+
104+
$response = $this->plugin->get( 'response' );
105+
if ( isset( $response->success ) && $response->success ) {
106+
JResponse::setHeader( 'status', 200, true );
107+
$response->code = 200;
108+
$this->plugin->setResponse( $response );
109+
}*/
110+
}
111+
112+
function qry()
113+
{
114+
$db = &JFactory::getDBO();
115+
$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'))";
116+
$db->setQuery( $query );
117+
$total = $db->loadResult();
118+
}
119+
120+
}

0 commit comments

Comments
 (0)