Skip to content

Commit

Permalink
CPDB integration in installer
Browse files Browse the repository at this point in the history
Advance deletion in display participants
blacklist control stub
Permission system for cpdb


git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_ci@10740 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Aniessh Sethh committed Aug 15, 2011
1 parent b9fe31c commit 9664de6
Show file tree
Hide file tree
Showing 20 changed files with 1,130 additions and 517 deletions.
85 changes: 77 additions & 8 deletions application/controllers/admin/participants.php
Expand Up @@ -197,6 +197,26 @@ function editShareInfo()
'shared_uid' => $this->input->post('shared_uid'));
$this->participant_shares_model->updateShare($data);
}
function delParticipant()
{

$this->load->model('participants_model');
$selectoption = $this->input->post('selectedoption');
$participant_id = $this->input->post('participant_id');
if($selectoption=="po")
{
$this->participants_model->deleteParticipant($participant_id);
}
elseif($selectoption=="ptt")
{
$this->participants_model->deleteParticipantToken($participant_id);
}
else
{
$this->participants_model->deleteParticipantTokenAnswer($participant_id);
}

}
/*
* This function is resposible for editing data on the jqGrid
*/
Expand Down Expand Up @@ -224,7 +244,6 @@ function editParticipant()
}
if($operation == 'edit')
{

$data = array(
'participant_id' => $_POST['id'],
'firstname' => $_POST['firstname'],
Expand All @@ -235,10 +254,6 @@ function editParticipant()
'owner_uid' => $oid);
$this->participants_model->updateRow($data);
}
elseif($operation == 'del')
{
$this->participants_model->deleteRow($_POST);
}
elseif($operation == 'add')
{
$uuid = $this->gen_uuid();
Expand Down Expand Up @@ -954,8 +969,7 @@ function attributeMapCSV()
$errorinupload = array('error' => $this->upload->display_errors());
$this->session->unset_userdata('summary');
$data = array( 'errorinupload' => $errorinupload);

$this->session->set_userdata('summary',$data);
$this->session->set_userdata('summary',$data);
self::_getAdminHeader();
$clang = $this->limesurvey_lang;
$data = array('clang'=> $clang);
Expand Down Expand Up @@ -1459,6 +1473,61 @@ function attributeMapToken()
$this->load->view('admin/Participants/attributeMapToken_view',$data);
self::_getAdminFooter("http://docs.limesurvey.org", $this->limesurvey_lang->gT("LimeSurvey online manual"));
}

function isValidGuid($guid)
{
return (!empty($guid) && preg_match('/^\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}\}?$/', $guid));
}
function blacklistParticipant()
{
$this->load->model('participants_model');
$participant_id = $this->uri->segment(4);
$survey_id = $this->uri->segment(5);
$clang = $this->limesurvey_lang;
if(!is_numeric($survey_id))
{
$blacklist = $this->uri->segment(5);
if($blacklist=='Y' || $blacklist =='N')
{
$data = array('blacklisted' => $blacklist,'participant_id' => $participant_id );
$result = $this->participants_model->blacklistparticipantglobal($data);
$result['global'] = 1;
$result['clang'] = $clang;
$result['blacklist'] = $blacklist;
$this->load->view('admin/Participants/blacklist_view',$result);
}
else
{
$result['is_participant']=0;
$result['is_updated']=0;
$result['clang'] = $clang;
$this->load->view('admin/Participants/blacklist_view',$result);
}
}
else
{
$blacklist = $this->uri->segment(6);
if( $blacklist=='Y' || $blacklist =='N')
{
$data = array('blacklisted' => $blacklist);
$result = $this->participants_model->blacklistparticipantlocal($data,$survey_id,$participant_id);$result['global'] = 1;
$result['clang'] = $clang;
$result['local'] = 1;
$result['blacklist'] = $blacklist;
$this->load->view('admin/Participants/blacklist_view',$result);

}
else
{
$result['is_participant']=0;
$result['is_updated']=0;
$result['clang'] = $clang;
$this->load->view('admin/Participants/blacklist_view',$result);

}

}


}
}
?>
2 changes: 2 additions & 0 deletions application/controllers/admin/tokens.php
Expand Up @@ -748,6 +748,7 @@ function email($surveyid,$tokenids=null)

$attributes=GetTokenFieldsAndNames($surveyid);
$tokenoutput="";

if ($emcount > 0)
{
foreach ($emresult->result_array() as $emrow)
Expand Down Expand Up @@ -789,6 +790,7 @@ function email($surveyid,$tokenids=null)
}
else
{
echo "dfsA";
$fieldsarray["{OPTOUTURL}"]="<a href='$publicurl/optout.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}'>".htmlspecialchars("$publicurl/optout.php?lang=".trim($emrow['language'])."&sid=$surveyid&token={$emrow['token']}")."</a>";
if ( $modrewrite )
{
Expand Down
10 changes: 6 additions & 4 deletions application/controllers/admin/user.php
Expand Up @@ -60,7 +60,7 @@ function editusers()
//$uresult = db_execute_assoc($uquery); //Checked
$uresult = $this->users_model->getSomeRecords(array("users_name"),array("uid"=>$usrhimself['parent_id']));
$srow = $uresult->row_array();
//$usersummary .= "<td align='center'><strong>{$srow['users_name']}</strong></td>\n";
//$usersummary .= "<td align='center'><strong>{$srow['users_name']}</strong></td>\n";
}

$data['usrhimself']=$usrhimself;
Expand Down Expand Up @@ -136,13 +136,13 @@ function adduser()
db_execute_assoc($template_query); //Checked

// add new user to userlist
$squery = "SELECT uid, users_name, password, parent_id, email, create_survey, configurator, create_user, delete_user, superadmin, manage_template, manage_label FROM ".$this->db->dbprefix('users')." WHERE uid='{$newqid}'"; //added by Dennis
$squery = "SELECT uid, users_name, password, parent_id, email, create_survey, configurator, create_user, delete_user, participant_panel,superadmin, manage_template, manage_label FROM ".$this->db->dbprefix('users')." WHERE uid='{$newqid}'"; //added by Dennis
$sresult = db_execute_assoc($squery);//Checked
$srow = $sresult->row_array();
$userlist = getuserlist();
array_push($userlist, array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'],
"password"=>$srow["password"], "parent_id"=>$srow['parent_id'], // "level"=>$level,
"create_survey"=>$srow['create_survey'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'],
"create_survey"=>$srow['create_survey'],"participant_panel"=>$srow['participant_panel'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'],
"delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'],
"manage_label"=>$srow['manage_label']));

Expand Down Expand Up @@ -564,6 +564,7 @@ function userrights()

// Forbids Allowing more privileges than I have
if(isset($_POST['create_survey']) && $this->session->userdata('USER_RIGHT_CREATE_SURVEY'))$rights['create_survey']=1; else $rights['create_survey']=0;
if(isset($_POST['participant_panel']) && $this->session->userdata('USER_RIGHT_PARTICIPANT_PANEL'))$rights['participant_panel']=1; else $rights['participant_panel']=0;
if(isset($_POST['configurator']) && $this->session->userdata('USER_RIGHT_CONFIGURATOR'))$rights['configurator']=1; else $rights['configurator']=0;
if(isset($_POST['create_user']) && $this->session->userdata('USER_RIGHT_CREATE_USER'))$rights['create_user']=1; else $rights['create_user']=0;
if(isset($_POST['delete_user']) && $this->session->userdata('USER_RIGHT_DELETE_USER'))$rights['delete_user']=1; else $rights['delete_user']=0;
Expand All @@ -583,6 +584,7 @@ function userrights()
if(isset($_POST['create_survey']))$rights['create_survey']=1; else $rights['create_survey']=0;
if(isset($_POST['configurator']))$rights['configurator']=1; else $rights['configurator']=0;
if(isset($_POST['create_user']))$rights['create_user']=1; else $rights['create_user']=0;
if(isset($_POST['participant_panel']))$rights['participant_panel']=1; else $rights['participant_panel']=0;
if(isset($_POST['delete_user']))$rights['delete_user']=1; else $rights['delete_user']=0;

// Only Initial Superadmin can give this right
Expand All @@ -593,7 +595,7 @@ function userrights()
// Initial SuperAdmin has parent_id == 0
$adminquery = "SELECT uid FROM ".$this->db->dbprefix("users")." WHERE parent_id=0";
$adminresult = db_select_limit_assoc($adminquery, 1);
$row=$adminresult->FetchRow();
$row=$adminresult->row_array();

if($row['uid'] == $this->session->userdata('loginID')) // it's the original superadmin !!!
{
Expand Down
5 changes: 3 additions & 2 deletions application/core/AdminController.php
Expand Up @@ -320,16 +320,17 @@ function _GetSessionUserRights($loginID)
{
//$squery = "SELECT create_survey, configurator, create_user, delete_user, superadmin, manage_template, manage_label FROM {$dbprefix}users WHERE uid=$loginID";
$this->load->model("Users_model");
$query = $this->Users_model->getSomeRecords(array("create_survey, configurator, create_user, delete_user, superadmin, manage_template, manage_label"),array("uid"=>$loginID));
$query = $this->Users_model->getSomeRecords(array("create_survey, configurator, create_user, delete_user, superadmin,participant_panel, manage_template, manage_label"),array("uid"=>$loginID));
//$sresult = db_execute_assoc($squery); //Checked
//if ($sresult->RecordCount()>0)
if($query->num_rows() > 0)
{
//$fields = $sresult->FetchRow();
$fields = $query->row_array();
$this->session->set_userdata('USER_RIGHT_CREATE_SURVEY', $fields['create_survey']);
$this->session->set_userdata('USER_RIGHT_PARTICIPANT_PANEL', $fields['participant_panel']);
$this->session->set_userdata('USER_RIGHT_CONFIGURATOR', $fields['configurator']);
$this->session->set_userdata('USER_RIGHT_CREATE_USER', $fields['create_user']);
$this->session->set_userdata('USER_RIGHT_CREATE_USER', $fields['create_user']);
$this->session->set_userdata('USER_RIGHT_DELETE_USER', $fields['delete_user']);
$this->session->set_userdata('USER_RIGHT_SUPERADMIN', $fields['superadmin']);
$this->session->set_userdata('USER_RIGHT_MANAGE_TEMPLATE', $fields['manage_template']);
Expand Down
5 changes: 3 additions & 2 deletions application/helpers/common_helper.php
Expand Up @@ -1484,11 +1484,11 @@ function getuserlist($outputformat='fullinfoarray')
{
if ($srow['uid'] != $CI->session->userdata('loginID'))
{
$userlist[] = array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'], "password"=>$srow['password'], "full_name"=>$srow['full_name'], "parent_id"=>$srow['parent_id'], "create_survey"=>$srow['create_survey'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'], "delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'], "manage_label"=>$srow['manage_label']); //added by Dennis modified by Moses
$userlist[] = array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'], "password"=>$srow['password'], "full_name"=>$srow['full_name'], "parent_id"=>$srow['parent_id'], "create_survey"=>$srow['create_survey'], "participant_panel"=>$srow['participant_panel'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'], "delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'], "manage_label"=>$srow['manage_label']); //added by Dennis modified by Moses
}
else
{
$userlist[0] = array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'], "password"=>$srow['password'], "full_name"=>$srow['full_name'], "parent_id"=>$srow['parent_id'], "create_survey"=>$srow['create_survey'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'], "delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'], "manage_label"=>$srow['manage_label']);
$userlist[0] = array("user"=>$srow['users_name'], "uid"=>$srow['uid'], "email"=>$srow['email'], "password"=>$srow['password'], "full_name"=>$srow['full_name'], "parent_id"=>$srow['parent_id'], "create_survey"=>$srow['create_survey'],"participant_panel"=>$srow['participant_panel'], "configurator"=>$srow['configurator'], "create_user"=>$srow['create_user'], "delete_user"=>$srow['delete_user'], "superadmin"=>$srow['superadmin'], "manage_template"=>$srow['manage_template'], "manage_label"=>$srow['manage_label']);
}
}
else
Expand Down Expand Up @@ -3912,6 +3912,7 @@ function setuserrights($uid, $rights)
$CI->load->helper("database");
$updates = "create_survey=".$rights['create_survey']
. ", create_user=".$rights['create_user']
. ", participant_panel=".$rights['participant_panel']
. ", delete_user=".$rights['delete_user']
. ", superadmin=".$rights['superadmin']
. ", configurator=".$rights['configurator']
Expand Down
107 changes: 103 additions & 4 deletions application/models/participants_model.php
Expand Up @@ -33,24 +33,84 @@ function updateRow($data)
$this->db->where('participant_id',$data['participant_id']);
$this->db->update('participants',$data);
}
function deleteParticipantTokenAnswer($rows)
{
$rowid=explode(",",$rows);
//$rowid = array('243148a0-bf56-4ee1-a6d2-a1f1cb5243d5');
foreach($rowid as $row)
{
$this->db->where('participant_id',$row);
$tokens = $this->db->get('survey_links');
foreach($tokens->result_array() as $key => $value)
{
$this->db->where('participant_id',$row);
$this->db->delete('participants'); //Delete from participants
if($this->db->table_exists('tokens_'.$value['survey_id']))
{
$this->db->select('token');
$this->db->where('participant_id',$value['participant_id']);
$tokenid = $this->db->get('tokens_'.$value['survey_id']);
$token = $tokenid->row();
if($this->db->table_exists('survey_'.$value['survey_id']))
{
if(!empty($token->token))
{
$this->db->where('token',$tokenid->row()->token);
$gettoken=$this->db->get('survey_'.$value['survey_id']);
$this->db->where('token',$gettoken->row()->token);
$this->db->delete('survey_'.$value['survey_id']);
}
}
$this->db->where('participant_id',$value['participant_id']);
$this->db->delete('tokens_'.$value['survey_id']);// Deletes from token
}
}
}

}
function deleteParticipantToken($rows)
{
$rowid=explode(",",$rows);
foreach($rowid as $row)
{
$this->db->where('participant_id',$row);
$tokens = $this->db->get('survey_links');
foreach($tokens->result_array() as $key => $value)
{
if($this->db->table_exists('tokens_'.$value['survey_id']))
{
$this->db->where('participant_id',$value['participant_id']);
$this->db->delete('tokens_'.$value['survey_id']);
}
}
$this->db->where('participant_id',$row);
$this->db->delete('participants');
$this->db->where('participant_id',$row);
$this->db->delete('survey_links');
$this->db->where('participant_id',$row);
$this->db->delete('participant_attribute');
}

}
/*
* This function deletes the row marked in the navigator
* Parameters : row id's
* Return Data : None
*/
function deleteRow($rows)
function deleteParticipant($rows)
{
// Converting the comma seperated id's to an array to delete multiple rows
$rowid=explode(",",$rows['id']);
foreach($rowid as $row)
$rowid=explode(",",$rows);
foreach($rowid as $row)
{
$this->db->where('participant_id',$row);
$this->db->delete('participants');
$this->db->where('participant_id',$row);
$this->db->delete('participant_shares');
$this->db->delete('survey_links');
$this->db->where('participant_id',$row);
$this->db->delete('participant_attribute');
}

}
/*
* This function is responsible for adding the participant to the database from the CSV upload
Expand Down Expand Up @@ -1143,6 +1203,45 @@ function copytosurveyatt($surveyid,$mapped,$newcreate)
$returndata = array('success'=>$sucessfull,'duplicate'=>$duplicate);
return $returndata;
}
function blacklistparticipantglobal($data)
{
$this->db->where('participant_id',$data['participant_id']);
$this->db->get('participants');
$is_participant = $this->db->affected_rows();
$this->db->where('participant_id',$data['participant_id']);
$this->db->update('participants', $data);
$is_updated = $this->db->affected_rows();
$result = array('is_participant' => $is_participant,
'is_updated' => $is_updated );
return $result;

}
function blacklistparticipantlocal($data,$survey_id,$tid)
{
$is_survey = $this->db->table_exists('tokens_'.$survey_id);
if($is_survey)
{
$this->db->where('tid',$tid);
$this->db->get('tokens_'.$survey_id);
$is_participant = $this->db->affected_rows();
$this->db->where('tid',$tid);
$this->db->update('tokens_'.$survey_id, $data);
$is_updated = $this->db->affected_rows();
$result = array('is_participant' => $is_participant,
'is_updated' => $is_updated,
'is_survey' => $is_survey);
}
else
{
$is_survey = $this->db->table_exists('tokens_'.$survey_id);
$is_participant = "";
$is_updated="";
$result = array('is_participant' => $is_participant,
'is_updated' => $is_updated,
'is_survey' => $is_survey);
}
return $result;
}
}

?>

0 comments on commit 9664de6

Please sign in to comment.