/** * This function sends the shared participant info to the share panel using JSON encoding * This function is called after the share panel grid is loaded * This function returns the json depending on the user logged in by checking it from the session * @param it takes the session user data loginID * @return JSON encoded string containg sharing information */ function getTokens_json($iSurveyId, $search = null) { // CHECK TO SEE IF A TOKEN TABLE EXISTS FOR THIS SURVEY $bTokenExists = tableExists('{{tokens_' . $iSurveyId . '}}'); if (!$bTokenExists) { eT("No token table."); // return json ? error not treated in js. return; } if (!Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'read')) { eT("We are sorry but you don't have permissions to do this."); // return json ? error not treated in js. return; } $page = (int) Yii::app()->request->getPost('page', 1); $limit = (int) Yii::app()->request->getPost('rows', 25); $sidx = Yii::app()->request->getPost('sidx', 'lastname'); $sord = Yii::app()->request->getPost('sord', 'asc'); if (strtolower($sord) != 'desc') { $sord = 'asc'; } $aData = new stdClass(); $aData->page = $page; $aSearchArray = Yii::app()->request->getPost('searcharray'); if (empty($search) && !empty($aSearchArray)) { $search = $aSearchArray; } if (!empty($search)) { $condition = TokenDynamic::model($iSurveyId)->getSearchMultipleCondition($search); } else { $condition = new CDbCriteria(); } $condition->order = Yii::app()->db->quoteColumnName($sidx) . " " . $sord; $condition->offset = ($page - 1) * $limit; $condition->limit = $limit; $tokens = Token::model($iSurveyId)->findAll($condition); $condition->offset = 0; $condition->limit = 0; $aData->records = Token::model($iSurveyId)->count($condition); if ($limit > $aData->records) { $limit = $aData->records; } if ($limit != 0) { $aData->total = ceil($aData->records / $limit); } else { $aData->total = 0; } Yii::app()->loadHelper("surveytranslator"); $format = getDateFormatData(Yii::app()->session['dateformat']); $aSurveyInfo = Survey::model()->findByPk($iSurveyId)->getAttributes(); //Get survey settings $attributes = getAttributeFieldNames($iSurveyId); // Now find all responses for the visible tokens $visibleTokens = array(); $answeredTokens = array(); if ($aSurveyInfo['anonymized'] == "N" && $aSurveyInfo['active'] == "Y") { foreach ($tokens as $token) { if (isset($token['token']) && $token['token']) { $visibleTokens[] = $token['token']; } } $answers = SurveyDynamic::model($iSurveyId)->findAllByAttributes(array('token' => $visibleTokens)); foreach ($answers as $answer) { $answeredTokens[$answer['token']] = $answer['token']; } } $bReadPermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'read'); $bCreatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'responses', 'create'); $bTokenUpdatePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'update'); $bTokenDeletePermission = Permission::model()->hasSurveyPermission($iSurveyId, 'tokens', 'delete'); $bGlobalPanelReadPermission = Permission::model()->hasGlobalPermission('participantpanel', 'read'); foreach ($tokens as $token) { $aRowToAdd = array(); if ((int) $token['validfrom']) { $token['validfrom'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validfrom']))); } else { $token['validfrom'] = ''; } if ((int) $token['validuntil']) { $token['validuntil'] = date($format['phpdate'] . ' H:i', strtotime(trim($token['validuntil']))); } else { $token['validuntil'] = ''; } $aRowToAdd['id'] = $token['tid']; $action = ""; $action .= "<div class='inputbuttons'>"; // so we can hide this when edit is clicked // Check is we have an answer if (in_array($token['token'], $answeredTokens) && $bReadPermission) { // @@TODO change link $url = $this->getController()->createUrl("admin/responses/sa/browse/surveyid/{$iSurveyId}", array('token' => $token['token'])); $title = gT("View response details"); $action .= CHtml::link('<span class="inputbuttons-square glyphicon glyphicon-list-alt text-success" title="' . $title . '"></span>', $url, array('class' => 'imagelink')); } else { $action .= '<div style="width: 20px; height: 16px; float: left;"></div>'; } // Check if the token can be taken if ($token['token'] != "" && ($token['completed'] == "N" || $token['completed'] == "" || $aSurveyInfo['alloweditaftercompletion'] == "Y") && $bCreatePermission) { $action .= viewHelper::getIconLink('inputbuttons-square icon-do text-success', "survey/index/sid/{$iSurveyId}/token/{$token['token']}/lang/{$token['language']}/newtest/Y", gT("Do survey"), '_blank'); } else { $action .= '<div style="width: 20px; height: 16px; float: left;"></div>'; } // Add delete icon if ($bTokenDeletePermission) { $attribs = array('onclick' => 'if (confirm("' . gT("Are you sure you want to delete this entry?") . ' (' . $token['tid'] . ')")) {$("#displaytokens").delRowData(' . $token['tid'] . ');$.post(delUrl,{tid:' . $token['tid'] . '});}'); $action .= viewHelper::getIconLink('inputbuttons-square glyphicon glyphicon-trash text-warning', null, gT("Delete token entry"), null, 'imagelink btnDelete', $attribs); } // Add email button if (strtolower($token['emailstatus']) == 'ok' && $token['email'] && $bTokenUpdatePermission) { if ($token['completed'] == 'N' && $token['usesleft'] > 0) { if ($token['sent'] == 'N') { $action .= viewHelper::getIconLink('inputbuttons-square icon-invite text-success', "admin/tokens/sa/email/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], gT("Send invitation email to this person (if they have not yet been sent an invitation email)"), "_blank"); } else { $action .= viewHelper::getIconLink('inputbuttons-square icon-remind text-success', "admin/tokens/sa/email/action/remind/surveyid/{$iSurveyId}/tokenids/" . $token['tid'], gT("Send reminder email to this person (if they have already received the invitation email)"), "_blank"); } } else { $action .= '<div style="width: 20px; height: 16px; float: left;"></div>'; } } else { $action .= '<div style="width: 20px; height: 16px; float: left;"></div>'; } // Add edit button if ($bTokenUpdatePermission) { $action .= viewHelper::getIconLink('inputbuttons-square glyphicon glyphicon-pencil text-success', null, gT("Edit token entry"), null, 'imagelink token_edit'); } // Add view button? if (!empty($token['participant_id']) && $token['participant_id'] != "" && $bGlobalPanelReadPermission) { $action .= viewHelper::getIconLink('inputbuttons-square icon-cpdb text-success', null, gT("View this person in the central participants database"), null, 'imagelink cpdb', array('onclick' => "sendPost('" . $this->getController()->createUrl('admin/participants/sa/displayParticipants') . "','',['searchcondition'],['participant_id||equal||{$token['participant_id']}']);")); } else { $action .= '<div style="width: 20px; height: 16px; float: left;"></div>'; } $action .= '</div>'; $aRowToAdd['cell'] = array($token['tid'], $action, htmlspecialchars($token['firstname'], ENT_QUOTES), htmlspecialchars($token['lastname'], ENT_QUOTES), htmlspecialchars($token['email'], ENT_QUOTES), htmlspecialchars($token['emailstatus'], ENT_QUOTES), htmlspecialchars($token['token'], ENT_QUOTES), htmlspecialchars($token['language'], ENT_QUOTES), htmlspecialchars($token['sent'], ENT_QUOTES), htmlspecialchars($token['remindersent'], ENT_QUOTES), htmlspecialchars($token['remindercount'], ENT_QUOTES), htmlspecialchars($token['completed'], ENT_QUOTES), htmlspecialchars($token['usesleft'], ENT_QUOTES), htmlspecialchars($token['validfrom'], ENT_QUOTES), htmlspecialchars($token['validuntil'], ENT_QUOTES)); foreach ($attributes as $attribute) { $aRowToAdd['cell'][] = htmlspecialchars($token[$attribute], ENT_QUOTES); } $aData->rows[] = $aRowToAdd; } viewHelper::disableHtmlLogging(); header("Content-type: application/json"); echo ls_json_encode($aData); }