From 9ca2973e39b5a59cfd18b5fac61a8de5fcf8febd Mon Sep 17 00:00:00 2001 From: Shubham Sachdeva Date: Fri, 2 Dec 2011 07:30:52 +0000 Subject: [PATCH] PORT THE FUNCTIONALITY 'CREATE/EDIT/DELETE USER GROUPS' TO THE YII PHP FRAMEWORK : Done by GCI participant Ivan Penchev git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11563 b72ed6b6-b9f8-46b5-92b4-906544132732 --- application/controllers/AdminController.php | 1 + application/controllers/admin/usergroups.php | 305 ++++++++++-------- application/helpers/common_helper.php | 12 +- application/helpers/database_helper.php | 63 ++-- application/models/User_groups.php | 159 +++++++++ application/models/User_in_groups.php | 100 ++++++ .../admin/usergroup/addUserGroup_view.php | 2 +- .../admin/usergroup/editUserGroup_view.php | 6 +- .../admin/usergroup/usergroupbar_view.php | 44 +-- 9 files changed, 502 insertions(+), 190 deletions(-) create mode 100644 application/models/User_groups.php create mode 100644 application/models/User_in_groups.php diff --git a/application/controllers/AdminController.php b/application/controllers/AdminController.php index 7d76b0a3a2f..2647d0f5fa1 100644 --- a/application/controllers/AdminController.php +++ b/application/controllers/AdminController.php @@ -110,6 +110,7 @@ public function actions() 'index' => 'application.controllers.admin.index', 'globalsettings' => 'application.controllers.admin.globalsettings', 'quotas' => 'application.controllers.admin.quotas', + 'usergroups' => 'application.controllers.admin.usergroups', 'export' => 'application.controllers.admin.export', 'assessments' =>'application.controllers.admin.assessments', 'checkintegrity' => 'application.controllers.admin.checkintegrity', diff --git a/application/controllers/admin/usergroups.php b/application/controllers/admin/usergroups.php index 32960a8a427..f3b8de7e001 100644 --- a/application/controllers/admin/usergroups.php +++ b/application/controllers/admin/usergroups.php @@ -23,18 +23,29 @@ * @version $Id: usergroups.php 11128 2011-10-08 22:23:24Z dionet $ * @access public */ -class Usergroups extends Admin_Controller { - - /** - * Usergroups::__construct() - * Constructor - * @return - */ - function __construct() - { - parent::__construct(); - } +class Usergroups extends CAction { + + private $yii; + private $controller; + + public function run() + { + $actions = array_keys($_GET); + $_GET['method'] = $action = (!empty($actions[0])) ? $actions[0] : ''; + + $this->yii = Yii::app(); + $this->controller = $this->getController(); + + if(!empty($action)) + { + $this->$action($_GET[$action]); + } + else + { + $this->view(); + } + } /** * Usergroups::mail() @@ -86,7 +97,7 @@ function mail($ugid) $addressee = substr("$addressee", 0, -2); $this->load->model('users'); - $from_user_result = $this->users_model->getSomeRecords(array('email', 'users_name', 'full_name'), array('uid' => $this->session->userdata('loginID')); + $from_user_result = $this->users_model->getSomeRecords(array('email', 'users_name', 'full_name'), array('uid' => $this->session->userdata('loginID'))); $from_user_row = $from_user_result->row_array(); if ($from_user_row['full_name']) { @@ -155,6 +166,7 @@ function mail($ugid) $crow = $result->row_array(); $data['clang'] = $clang; + $this->load->view("admin/usergroup/mailUserGroup_view",$data); } @@ -169,19 +181,17 @@ function mail($ugid) * Function responsible to delete a user group. * @return */ - function delete() + public function delete() { - - $clang = $this->limesurvey_lang; - - - $css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css"; - $this->config->set_item("css_admin_includes", $css_admin_includes); - self::_js_admin_includes(base_url().'scripts/admin/users.js'); - self::_getAdminHeader(); - self::_showadminmenu(false); - $action = $this->input->post("action"); - $ugid = $this->input->post("ugid"); + $clang = $this->yii->lang; + + $css_admin_includes[] = $this->yii->getConfig('styleurl')."admin/default/superfish.css"; + $this->yii->setConfig("css_admin_includes", $css_admin_includes); + $this->controller->_js_admin_includes($this->yii->baseUrl.'scripts/admin/users.js'); + $this->controller->_getAdminHeader(); + $this->controller->_showadminmenu(false); + $action = $_POST['action']; + $ugid = $_POST['ugid']; self::_usergroupbar($ugid); if ($action == "delusergroup") @@ -189,29 +199,35 @@ function delete() $usersummary = "
".$clang->gT("Deleting User Group")."...
\n"; $usersummary .= "
\n"; - if ($this->session->userdata('USER_RIGHT_SUPERADMIN') == 1) + if ($this->yii->session['USER_RIGHT_SUPERADMIN'] == 1) { if(!empty($ugid) && ($ugid > -1)) { - - $this->load->model('user_groups'); - $result = $this->user_groups_model->getSomeRecords(array('ugid', 'name', 'owner_id'), array('ugid' => $ugid, 'owner_id' => $this->session->userdata('loginID'))); - if($result->num_rows() > 0) + $query = 'SELECT ugid, name, owner_id FROM '.$this->yii->db->tablePrefix.'user_groups WHERE ugid=\''.$ugid.'\' AND owner_id=\''.$this->yii->session['loginID'].'\''; + //$this->load->model('user_groups'); + //$result = $this->user_groups_model->getSomeRecords(array('ugid', 'name', 'owner_id'), array('ugid' => $ugid, 'owner_id' => $this->session->userdata('loginID'))); + $result = db_execute_assoc($query); + if($result->count() > 0) { - $row = $result->row_array(); - - $remquery = $this->user_groups_model->delete(array('owner_id' => $this->session->userdata('loginID'), 'ugid' => $ugid)); - if($remquery) //Checked) + $row = $result->readAll(); + + $del_query = 'DELETE FROM '.$this->yii->db->tablePrefix.'user_groups WHERE owner_id=\''.$this->yii->session['loginID'].'\' AND ugid='.$ugid; + //$remquery = $this->user_groups_model->delete(array('owner_id' => $this->session->userdata('loginID'), 'ugid' => $ugid)); + $delquery_result = db_execute_assoc($del_query); + + $del_user_in_groups_query = "DELETE FROM ".$this->yii->db->tablePrefix."user_in_groups WHERE ugid=$ugid AND uid=".$this->yii->session['loginID']; + + if($delquery_result) //Checked) { - $usersummary .= "
".$clang->gT("Group Name").": {$row['name']}

\n"; + $usersummary .= "
".$clang->gT("Group Name").": {$row[0]['name']}

\n"; $usersummary .= "
".$clang->gT("Success!")."
\n"; } else { $usersummary .= "
".$clang->gT("Could not delete user group.")."
\n"; } - $link = site_url("admin/usergroups/view"); + $link = $this->controller->createUrl("admin/usergroups/view"); $usersummary .= "
gT("Continue")."\"/>\n"; } else @@ -221,7 +237,7 @@ function delete() } else { - $link = site_url("admin/usergroups/view"); + $link = $this->controller->createUrl("admin/usergroups/view"); $usersummary .= "
".$clang->gT("Could not delete user group. No group selected.")."
\n"; $usersummary .= "
gT("Continue")."\"/>\n"; } @@ -230,13 +246,12 @@ function delete() $displaydata['display'] = $usersummary; //$data['display'] = $editsurvey; - $this->load->view('survey_view',$displaydata); + $this->controller->render('/survey_view', $displaydata); } - self::_loadEndScripts(); - - - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + $this->controller->_loadEndScripts(); + + $this->controller->_getAdminFooter("http://docs.limesurvey.org", $this->yii->lang->gT("LimeSurvey online manual")); } @@ -246,30 +261,30 @@ function delete() * Load add user group screen. * @return */ - function add() + public function add() { - $clang = $this->limesurvey_lang; - - - $css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css"; - $this->config->set_item("css_admin_includes", $css_admin_includes); - self::_js_admin_includes(base_url().'scripts/admin/users.js'); - self::_getAdminHeader(); - self::_showadminmenu(false); - $action = $this->input->post("action"); - if ($this->session->userdata('USER_RIGHT_SUPERADMIN') == 1) + $clang = $this->yii->lang; + + $css_admin_includes[] = $this->yii->getConfig('styleurl')."admin/default/superfish.css"; + $this->yii->setConfig("css_admin_includes", $css_admin_includes); + $this->controller->_js_admin_includes($this->yii->baseUrl.'scripts/admin/users.js'); + $this->controller->_getAdminHeader(); + $this->controller->_showadminmenu(false); + $action = (isset($_POST['action'])) ? $_POST['action'] : ''; + + if ($this->yii->session['USER_RIGHT_SUPERADMIN'] == 1) { self::_usergroupbar(false); $data['clang'] = $clang; + if ($action == "usergroupindb") { $usersummary = "
".$clang->gT("Adding User Group")."...
\n"; $usersummary .= "
\n"; - if ($this->session->userdata('USER_RIGHT_SUPERADMIN') == 1) + if ($this->yii->session['USER_RIGHT_SUPERADMIN'] == 1) { - $_POST = $this->input->post(); $db_group_name = $_POST['group_name']; $db_group_description = $_POST['group_description']; $html_group_name = htmlspecialchars($_POST['group_name']); @@ -279,7 +294,7 @@ function add() { if (strlen($db_group_name) > 21) { - $link = site_url("admin/usergroups/add"); + $link = $this->controller->createUrl("admin/usergroups/add"); $usersummary .= "
".$clang->gT("Failed to add Group!")."
\n" . "
" . $clang->gT("Group name length more than 20 characters!")."
\n"; //need to nupdate translations for this phrase. $usersummary .= "
gT("Continue")."\"/>\n"; @@ -296,13 +311,13 @@ function add() { $usersummary .= $clang->gT("Description: ").$html_group_description."

\n"; } - $link = site_url("admin/usergroups/view/$ugid"); + $link = $this->controller->createUrl("admin/usergroups/view/$ugid"); $usersummary .= "
".$clang->gT("User group successfully added!")."
\n"; $usersummary .= "
gT("Continue")."\"/>\n"; } else { - $link = site_url("admin/usergroups/add"); + $link = $this->controller->createUrl("admin/usergroups/add"); $usersummary .= "
".$clang->gT("Failed to add Group!")."
\n" . "
" . $clang->gT("Group already exists!")."
\n"; $usersummary .= "
gT("Continue")."\"/>\n"; @@ -312,33 +327,31 @@ function add() } else { - $link = site_url("admin/usergroups/add"); + $link = $this->controller->createUrl("admin/usergroups/add"); $usersummary .= "
".$clang->gT("Failed to add Group!")."
\n" . "
" . $clang->gT("Group name was not supplied!")."
\n"; $usersummary .= "
gT("Continue")."\"/>\n"; } } else - { - //include("access_denied.php"); - } + {} $usersummary .= "
\n"; $displaydata['display'] = $usersummary; //$data['display'] = $editsurvey; - $this->load->view('survey_view',$displaydata); + $this->controller->render('/survey_view', $displaydata); } else { - $this->load->view("admin/usergroup/addUserGroup_view",$data); + $this->controller->render('/admin/usergroup/addUserGroup_view', $data); } } - self::_loadEndScripts(); + + $this->controller->_loadEndScripts(); - - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + $this->controller->_getAdminFooter("http://docs.limesurvey.org", $this->yii->lang->gT("LimeSurvey online manual")); } @@ -351,25 +364,24 @@ function add() function edit($ugid) { $ugid = (int) $ugid; - $clang = $this->limesurvey_lang; + $clang = $this->yii->lang; - $css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css"; - $this->config->set_item("css_admin_includes", $css_admin_includes); - self::_js_admin_includes(base_url().'scripts/admin/users.js'); - self::_getAdminHeader(); - self::_showadminmenu(false); - $action = $this->input->post("action"); + $css_admin_includes[] = $this->yii->getConfig('styleurl')."admin/default/superfish.css"; + $this->yii->setConfig("css_admin_includes", $css_admin_includes); + $this->controller->_js_admin_includes($this->yii->baseUrl.'scripts/admin/users.js'); + $this->controller->_getAdminHeader(); + $this->controller->_showadminmenu(false); + $action = (isset($_POST['action'])) ? $_POST['action'] : ''; - if ($this->session->userdata('USER_RIGHT_SUPERADMIN') == 1) + if ($this->yii->session['USER_RIGHT_SUPERADMIN'] == 1) { self::_usergroupbar($ugid); $data['clang'] = $clang; if ($action == "editusergroupindb") { - $_POST = $this->input->post(); - if ($this->session->userdata('USER_RIGHT_SUPERADMIN') == 1) + if ($this->yii->session['USER_RIGHT_SUPERADMIN'] == 1) { $ugid = $_POST['ugid']; @@ -382,8 +394,9 @@ function edit($ugid) if(self::_updateusergroup($db_name, $db_description, $ugid)) { - $link = site_url("admin/usergroups/view/$ugid"); + $link = $this->controller->createUrl("admin/usergroups/view/$ugid"); $usersummary .= "
".$clang->gT("Edit User Group Successfully!")."
\n" + . "
".$clang->gT("Name").": {$html_name}
\n" . $clang->gT("Description: ").$html_description."
\n" . "
gT("Continue")."\"/>\n"; @@ -391,7 +404,7 @@ function edit($ugid) } else { - $link = site_url("admin/usergroups/view"); + $link = $this->createUrl("admin/usergroups/view"); $usersummary .= "
".$clang->gT("Failed to update!")."
\n" . "
gT("Continue")."\"/>\n"; //. "
".$clang->gT("Continue")."
 \n"; @@ -400,7 +413,7 @@ function edit($ugid) $displaydata['display'] = $usersummary; //$data['display'] = $editsurvey; - $this->load->view('survey_view',$displaydata); + $this->controller->render('/survey_view', $displaydata); } else @@ -412,20 +425,22 @@ function edit($ugid) } else { - $this->load->model('user_groups'); - $result = $this->user_groups_model->getAllRecords(array('ugid' => $ugid, 'owner_id' => $this->session->userdata('loginID'))); - $esrow = $result->row_array(); - $data['esrow'] = $esrow; + $query = 'SELECT * FROM '.$this->yii->db->tablePrefix.'user_groups WHERE ugid='.$ugid.' AND owner_id='.$this->yii->session['loginID']; + $result = db_execute_assoc($query); + /*$this->load->model('user_groups'); + $result = $this->user_groups_model->getAllRecords(array('ugid' => $ugid, 'owner_id' => $this->session->userdata('loginID')));*/ + $esrow = $result->readAll(); + $data['esrow'] = $esrow[0]; $data['ugid'] = $ugid; - $this->load->view("admin/usergroup/editUserGroup_view",$data); + $this->controller->render("/admin/usergroup/editUserGroup_view", $data); } } - self::_loadEndScripts(); + $this->controller->_loadEndScripts(); - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + $this->controller->_getAdminFooter("http://docs.limesurvey.org", $this->yii->lang->gT("LimeSurvey online manual")); } @@ -439,18 +454,17 @@ function edit($ugid) function view($ugid=false) { if($ugid!=false) $ugid = (int) $ugid; - $clang = $this->limesurvey_lang; + $clang = $this->yii->lang; - - $css_admin_includes[] = $this->config->item('styleurl')."admin/default/superfish.css"; - $this->config->set_item("css_admin_includes", $css_admin_includes); - self::_js_admin_includes(base_url().'scripts/admin/users.js'); - self::_getAdminHeader(); - self::_showadminmenu(false); + $css_admin_includes[] = $this->yii->getConfig('styleurl')."admin/default/superfish.css"; + $this->yii->setConfig("css_admin_includes", $css_admin_includes); + $this->controller->_js_admin_includes($this->yii->baseUrl.'scripts/admin/users.js'); + $this->controller->_getAdminHeader(); + $this->controller->_showadminmenu(false); self::_usergroupbar($ugid); - if ( $this->session->userdata('loginID')) + if ( $this->yii->session['loginID']) { if($ugid) @@ -458,20 +472,23 @@ function view($ugid=false) $ugid = sanitize_int($ugid); - $this->load->model('user_groups'); + //$this->user_groups_model = new User_groups; + + $query = "SELECT a.ugid, a.name, a.owner_id, a.description, b.uid FROM ".$this->yii->db->tablePrefix."user_groups AS a LEFT JOIN ".$this->yii->db->tablePrefix."user_in_groups AS b ON a.ugid = b.ugid WHERE a.ugid = {$ugid} AND uid = ".$this->yii->session['loginID']." ORDER BY name"; + //$select = array('a.ugid', 'a.name', 'a.owner_id', 'a.description', 'b.uid'); + //$join = array('where' => 'user_in_groups AS b', 'type' => 'left', 'on' => 'a.ugid = b.ugid'); + //$where = array('uid' => $this->session->userdata('loginID'), 'a.ugid' => $ugid); - $select = array('a.ugid', 'a.name', 'a.owner_id', 'a.description', 'b.uid'); - $join = array('where' => 'user_in_groups AS b', 'type' => 'left', 'on' => 'a.ugid = b.ugid'); - $where = array('uid' => $this->session->userdata('loginID'), 'a.ugid' => $ugid); + $result = db_execute_assoc($query)->readAll(); - $result = $this->user_groups_model->join($select, 'user_groups AS a', $where, $join, 'name'); - $crow = $result->row_array(); + //$result = $this->user_groups_model->join($select, 'user_groups AS a', $where, $join, 'name'); + $crow = $result[0]; - if($result->num_rows() > 0) + if($result) { - + $usergroupsummary = ''; if(!empty($crow['description'])) - { + $usergroupsummary = "\n" . "
" . "".$clang->gT("Description: ")."" @@ -479,11 +496,11 @@ function view($ugid=false) . "
"; } - $this->load->model('user_in_groups'); + //$this->user_in_groups_model = new User_in_groups; - $where = array('ugid' => $ugid); - $join = array('where' => 'users AS b', 'type' => 'inner', 'on' => 'a.uid = b.uid'); - $eguresult = $this->user_in_groups_model->join(array('*'), 'user_in_groups AS a', $where, $join, 'b.users_name'); + $eguquery = "SELECT * FROM ".$this->yii->db->tablePrefix."user_in_groups AS a INNER JOIN ".$this->yii->db->tablePrefix."users AS b ON a.uid = b.uid WHERE ugid = " . $ugid . " ORDER BY b.users_name"; + $eguresult = db_execute_assoc($eguquery); + $usergroupsummary .= "\n" . "\n" . "\n" @@ -491,12 +508,13 @@ function view($ugid=false) . "\n" . "\n"; - $result2 = $this->user_groups_model->getSomeRecords(array('ugid'), array('ugid' => $ugid, 'owner_id' => $this->session->userdata('loginID'))); - $row2 = $result2->row_array(); + $query2 = "SELECT ugid FROM ".$this->yii->db->tablePrefix."user_groups WHERE ugid = ".$ugid." AND owner_id = ".$this->yii->session['loginID']; + $result2 = db_select_limit_assoc($query2, 1); + $row2 = $result2->readAll(); $row = 1; $usergroupentries=''; - foreach ($eguresult->result_array() as $egurow) + foreach ($eguresult->readAll() as $egurow) { if (!isset($bgcc)) {$bgcc="evenrow";} else @@ -520,26 +538,28 @@ function view($ugid=false) $usergroupentries .= "\n" . "\n"; $usergroupentries .= "\n" . "\n" + . "\n"; $row++; } $usergroupsummary .= $usergroupowner; if (isset($usergroupentries)) {$usergroupsummary .= $usergroupentries;}; $usergroupsummary .= '
".$clang->gT("Action")."".$clang->gT("Email")."
\n"; - if($this->session->userdata('USER_RIGHT_SUPERADMIN') == 1) + if($this->yii->session['USER_RIGHT_SUPERADMIN'] == 1) { $usergroupentries .= "
" - ." " + ." " ." " ." " + ." "; } $usergroupentries .= "
" . "
{$egurow['users_name']}{$egurow['email']}
'; - - if(isset($row2['ugid'])) + + if(isset($row2[0]['ugid'])) { $usergroupsummary .= "
\n" . "\n" @@ -555,25 +575,22 @@ function view($ugid=false) $displaydata['display'] = $usergroupsummary; //$data['display'] = $editsurvey; - $this->load->view('survey_view',$displaydata); + $this->controller->render('/survey_view',$displaydata); } else { //include("access_denied.php"); } - } - } + } else { //include("access_denied.php"); } - self::_loadEndScripts(); - - - self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual")); + $this->controller->_loadEndScripts(); + $this->controller->_getAdminFooter("http://docs.limesurvey.org", $this->yii->lang->gT("LimeSurvey online manual")); } @@ -586,16 +603,17 @@ function view($ugid=false) */ function _usergroupbar($ugid=false) { - + $data['clang'] = $this->yii->lang; + $this->yii->loadHelper('database'); if($ugid) { - $this->load->model('user_groups'); + $grpquery = "SELECT gp.* FROM ".$this->yii->db->tablePrefix."user_groups AS gp, ".$this->yii->db->tablePrefix."user_in_groups AS gu WHERE gp.ugid=gu.ugid AND gp.ugid = $ugid AND gu.uid=".$this->yii->session['loginID']; + $grpresult = db_execute_assoc($grpquery); + $grpresultcount = db_records_count($grpquery); - $where = array('gp.ugid' => 'gu.ugid', 'gp.ugid' => $ugid, 'gu.uid' => $this->session->userdata('loginID')); - $grpresultcount = $this->user_groups_model->multi_select(array('gp.*'), array('user_groups AS gp', 'user_in_groups AS gu'), $where); if ($grpresultcount>0) { - $grow = array_map('htmlspecialchars', $grpresult->row_array()); + $grow = array_map('htmlspecialchars', $grpresult->read()); } $data['grow'] = $grow; @@ -606,7 +624,7 @@ function _usergroupbar($ugid=false) $data['ugid'] = $ugid; - $this->load->view('admin/usergroup/usergroupbar_view',$data); + $this->controller->render('/admin/usergroup/usergroupbar_view',$data); } /** @@ -619,9 +637,10 @@ function _usergroupbar($ugid=false) */ function _updateusergroup($name, $description, $ugid) { - $this->load->model('user_groups'); - $uquery = $this->user_groups_model->update(array('name' => $name, 'description' => $description), array('ugid' => $ugid)); - // TODO + $query = 'UPDATE '.$this->yii->db->tablePrefix.'user_groups SET name=\''.$name.'\', description=\''.$description.'\' WHERE ugid=\''.$ugid.'\''; + //$this->load->model('user_groups'); + //$uquery = $this->user_groups_model->update(array('name' => $name, 'description' => $description), array('ugid' => $ugid)); + $uquery = db_execute_assoc($query); return $uquery; //or safe_die($connect->ErrorMsg()) ; //Checked) } @@ -666,22 +685,30 @@ function _refreshtemplates() { * @return */ function _addUserGroupInDB($group_name, $group_description) { - - //$iquery = "INSERT INTO ".$this->db->dbprefix."user_groups (name, description, owner_id) VALUES('{$group_name}', '{$group_description}', '{$_SESSION['loginID']}')"; - $data = array( + $connect= $this->yii->db; + $iquery = "INSERT INTO ".$this->yii->db->tablePrefix."user_groups (`name`, `description`, `owner_id`) VALUES('{$group_name}', '{$group_description}', '{$_SESSION['loginID']}')"; + $command = $connect->createCommand($iquery); + $result = $command->query(); + /*$data = array( 'name' => $group_name, 'description' => $group_description, 'owner_id' => $this->session->userdata('loginID') ); $this->load->model('user_groups_model'); - $this->load->model('user_in_groups_model'); - - - if($this->user_groups_model->insertRecords($data)) { //Checked - $id = $this->db->insert_id(); //$connect->Insert_Id(db_table_name_nq('user_groups'),'ugid'); + $this->load->model('user_in_groups_model');*/ + + if($result) { //Checked + $id = $connect->getLastInsertID(); //$connect->Insert_Id(db_table_name_nq('user_groups'),'ugid'); + if($id > 0) { - $this->user_in_groups_model->insert('ugid' => $id, 'uid' => $this->session->userdata('loginID')); + $user_in_groups_query = 'INSERT INTO '.$this->yii->db->tablePrefix.'user_in_groups (ugid, uid) VALUES ('.$id.','.$this->yii->session['loginID'].')'; + db_execute_assoc($user_in_groups_query); + /*$this->user_in_groups_model = new User_in_groups; + $this->user_in_groups_model->ugid = $id; + $this->user_in_groups_model->uid = $this->yii->session['loginID']; + $this->user_in_groups_model->save();*/ + //$this->user_in_groups_model->insert(array('ugid' => $id, 'uid' => $this->session->userdata('loginID'))); } return $id; } else { diff --git a/application/helpers/common_helper.php b/application/helpers/common_helper.php index 648c8397b18..52f29cbc955 100644 --- a/application/helpers/common_helper.php +++ b/application/helpers/common_helper.php @@ -237,6 +237,7 @@ function getqtypelist($SelectedCode = "T", $ReturnType = "selector") 'answerscales'=>0), ); asort($qtypes); + if ($ReturnType == "array") {return $qtypes;} if ($ReturnType == "group"){ foreach($qtypes as $qkey=>$qtype){ @@ -7773,17 +7774,18 @@ function getusergrouplist($ugid=NULL,$outputformat='optionlist') function getgroupuserlist($ugid) { - $CI =& get_instance(); - $CI->load->helper('database'); - $clang = $CI->limesurvey_lang; + $yii = Yii::app(); + + $yii->loadHelper('database'); + $clang = $yii->lang; $ugid=sanitize_int($ugid); - $surveyidquery = "SELECT a.uid, a.users_name FROM ".$CI->db->dbprefix."users AS a LEFT JOIN (SELECT uid AS id FROM ".$CI->db->dbprefix."user_in_groups WHERE ugid = {$ugid}) AS b ON a.uid = b.id WHERE id IS NULL ORDER BY a.users_name"; + $surveyidquery = "SELECT a.uid, a.users_name FROM ".$yii->db->tablePrefix."users AS a LEFT JOIN (SELECT uid AS id FROM ".$yii->db->tablePrefix."user_in_groups WHERE ugid = {$ugid}) AS b ON a.uid = b.id WHERE id IS NULL ORDER BY a.users_name"; $surveyidresult = db_execute_assoc($surveyidquery); //Checked if (!$surveyidresult) {return "Database Error";} $surveyselecter = ""; - foreach ($surveyidresult->result_array() as $row) + foreach ($surveyidresult->readAll() as $row) { $surveynames[] = $row; } diff --git a/application/helpers/database_helper.php b/application/helpers/database_helper.php index 5f633661f32..3a3cda49cfb 100644 --- a/application/helpers/database_helper.php +++ b/application/helpers/database_helper.php @@ -3,21 +3,21 @@ function &db_execute_assoc($sql,$inputarr=false,$silent=false) { //$connect->SetFetchMode(ADODB_FETCH_ASSOC); - try { - if($inputarr) - { - $dataset=Yii::app()->db->createCommand($sql)->bindValues($inputarr)->query(); //Checked - } - else - { - $dataset=Yii::app()->db->createCommand($sql)->query(); + /*try { */ + if($inputarr) + { + $dataset=Yii::app()->db->createCommand($sql)->bindValues($inputarr)->query(); //Checked + } + else + { + $dataset=Yii::app()->db->createCommand($sql)->query(); - } - } catch(CDbException $e) { + } + /*} catch(CDbException $e) { $dataset=false; - } + }*/ - if (!$silent && !$dataset) { safe_die('Error executing query in db_execute_assoc:'.$sql); } + //if (!$silent && !$dataset) { safe_die('Error executing query in db_execute_assoc:'.$sql); } return $dataset; } @@ -25,15 +25,15 @@ function &db_execute($sql,$inputarr=false,$silent=false) { //$connect->SetFetchMode(ADODB_FETCH_ASSOC); try { - if($inputarr) - { - $affected=Yii::app()->db->createCommand($sql)->bindValues($inputarr)->execute(); //Checked - } - else - { - $affected=Yii::app()->db->createCommand($sql)->execute(); + if($inputarr) + { + $affected=Yii::app()->db->createCommand($sql)->bindValues($inputarr)->execute(); //Checked + } + else + { + $affected=Yii::app()->db->createCommand($sql)->execute(); - } + } } catch(CDbException $e) { $affected=false; } @@ -52,6 +52,29 @@ function &db_query_or_false($sql) return $dataset; } +/** + * Returns the number of records found in the database + * + * @param string $sql + * @return int +*/ +function &db_records_count($sql) +{ + $yii = Yii::app(); + $count = 0; + try + { + $result = $yii->db->createCommand($sql)->query(); + $count = $result->count(); + } + catch(CDbException $e) + { + $count = FALSE; + } + + return $count; +} + function &db_select_limit_assoc($sql,$numrows=0,$offset=0,$inputarr=false,$dieonerror=true) { //$connect->SetFetchMode(ADODB_FETCH_ASSOC); diff --git a/application/models/User_groups.php b/application/models/User_groups.php new file mode 100644 index 00000000000..e47b097ebdd --- /dev/null +++ b/application/models/User_groups.php @@ -0,0 +1,159 @@ +connection = Yii::app()->db; + if ($condition != FALSE) + { + $where_clause = array("WHERE"); + + foreach($condition as $key=>$val) + { + $where_clause[] = $key.'=\''.$val.'\''; + } + + $where_string = implode(' AND ', $where_clause); + } + + $query = 'SELECT * FROM '.$this->tableName().' '.$where_string; + + $data = createCommand($query)->query()->resultAll(); + + return $data; + } + + function getSomeRecords($fields,$condition=FALSE, $params=NULL) + { + $filter = new CDbCriteria; + + foreach ($fields as $field) + { + $filter->select[] = $field; + } + + if ($condition != FALSE) + { + $filter->condition = $condition; + $filter->params = $params; + } + + $data = $this->findAll($filter); + + return $data; + } + + /*function insertRecords($data) + { + + return $this->db->insert('user_groups',$data); + } + + function join($fields, $from, $condition=FALSE, $join=FALSE, $order=FALSE) + { + foreach ($fields as $field) + { + $this->db->select($field); + } + + $this->db->from($from); + + if ($condition != FALSE) + { + $this->db->where($condition); + } + + if ($order != FALSE) + { + $this->db->order_by($order); + } + + if (isset($join['where'], $join['type'], $join['on'])) + { + $this->db->join($condition); + } + + $data = $this->db->get(); + return $data; + } + + function multi_select($fields, $from, $condition=FALSE) + { + foreach ($fields as $field) + { + $this->db->select($field); + } + + foreach ($from AS $f) + { + $this->db->from($f); + } + + if ($condition != FALSE) + { + $this->db->where($condition); + } + + if ($order != FALSE) + { + $this->db->order_by($order); + } + + if (isset($join['where'], $join['type'], $join['on'])) + { + $this->db->join($condition); + } + + $data = $this->db->get(); + return $data; + } + + function update($what, $where=FALSE) + { + if ($where != FALSE) $this->db->where($where); + return (bool) $this->db->update('user_groups', $what); + } + + function delete($condition) + { + return (bool) $this->db->delete('user_groups', $condition); + }*/ + +} diff --git a/application/models/User_in_groups.php b/application/models/User_in_groups.php new file mode 100644 index 00000000000..e9e9054dabb --- /dev/null +++ b/application/models/User_in_groups.php @@ -0,0 +1,100 @@ +db->where($condition); + } + + $data = $this->db->get('user_in_groups'); + + return $data; + } + + function getSomeRecords($fields,$condition=FALSE) + { + foreach ($fields as $field) + { + $this->db->select($field); + } + if ($condition != FALSE) + { + $this->db->where($condition); + } + + $data = $this->db->get('user_in_groups'); + + return $data; + } + + function insert($data) + { + return (bool) $this->db->insert('user_in_groups', $data); + } + + function join($fields, $from, $condition=FALSE, $join=FALSE, $order=FALSE) + { + foreach ($fields as $field) + { + $this->db->select($field); + } + + $this->db->from($from); + + if ($condition != FALSE) + { + $this->db->where($condition); + } + + if ($order != FALSE) + { + $this->db->order_by($order); + } + + if (isset($join['where'], $join['type'], $join['on'])) + { + $this->db->join($condition); + } + + $data = $this->db->get(); + return $data; + }*/ + +} diff --git a/application/views/admin/usergroup/addUserGroup_view.php b/application/views/admin/usergroup/addUserGroup_view.php index 90f33c4ee26..33503127828 100644 --- a/application/views/admin/usergroup/addUserGroup_view.php +++ b/application/views/admin/usergroup/addUserGroup_view.php @@ -1,5 +1,5 @@
gT("Add User Group"); ?>
- +