Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • vtiger/vtigercrm
  • varma/vtigercrm
  • alanbell/vtigercrm
  • mariusz.krzaczkowski/vtigercrm
  • manu.k/vtigercrm
  • adrgranado/vtigercrm
  • uma.s/vtigercrm
  • sardoj/vtigercrm
  • preexo/vtigercrm
  • david.valminos/vtigercrm
  • luca.saba/vtigercrm
  • dubwise/vtigercrm
  • valmir.ttcasolucoes/vtigercrm
  • lord_alan/vtigercrm
  • adrien.futschik/vtigercrm
  • edonit.rexhepi/vtigercrm
  • robert.heinze/vtigercrm
  • nrdimatteo/vtigercrm
  • sebastianzahan/vtigercrm
  • Miky/vtigercrm
  • germanf/vtigercrm
  • bernhardkau1/vtigercrm
  • olegtsoy/vtigercrm
  • grandel/vtigercrm
  • mario.thummler/vtigercrm
  • sutharsan/vtigercrm
  • james.douglas/vtigercrm
  • vikas/vtigercrm
  • jeffmchristensen/vtigercrm
  • lukasz.g/vtigercrm
  • nicolas.gasnier/vtigercrm
  • hamish.theitcompany/vtigercrm
  • engrbm87/vtigercrm
  • Quoc/vtigercrm
  • peter.maria.engeli/vtigercrm
  • kiranraju.j/vtigercrm
  • manuel.lozano/vtigercrm
  • dhaupin/vtigercrm
  • Ragupathyranesh/vtigercrm
  • Stefanbauer/vtigercrm
  • ruben.estrada/vtigercrm
  • sg_mwi1/vtigercrm
  • khaluk/vtigercrm
  • franzfroemel/vtigercrm
  • milan9615/vtigercrm
  • carlos.martin/vtigercrm
  • cmaggi/vtigercrm
  • Soltoon.theLeader/vtigercrm
  • alex.kaplun/vtigercrm
  • navid.hosseini/vtigercrm
  • maie/vtigercrm
  • simonetravaglini/vtigercrm
  • bertrand.wattel/vtigercrm
  • balaji.m/vtigercrm
  • mclarke4/vtigercrm
  • lajeeshk/vtigercrm
  • liam/vtigercrm
  • novikov.sergey/vtigercrm
  • johnwayne.williamson/vtigercrm
  • florian.strahberger-schramm/vtigercrm
  • daniel.schaefer/vtigercrm
  • christopher.gunther/vtigercrm
  • adrien.faveraux/vtigercrm
  • carsten.brandt/vtigercrm
  • stephane.molano/vtigercrm
  • krastan.petrov/vtigercrm
  • alfredo.bravo/vtigercrm
  • flipflop.Joe/vtigercrm
  • mirko.stagni/vtigercrm
  • remigio.ruberto/vtigercrm
  • gautam.dhudashiya/vtigercrm
  • manish.devitechnosolutions1/vtigercrm
  • matinbeigi/vtigercrm
  • devs/vtigercrm
  • happy.dev/vtigercrm
  • m.gigon/vtigercrm
  • manuelmigone/vtigercrm
  • eduardo.gqf/vtigercrm
  • elsayedEl-araby/vtigercrm
  • mirza.mehran/vtigercrm
  • maurice.courtois/vtigercrm
  • zuhri.utama/vtigercrm
  • shilpa.k/vtigercrm
  • Ignazio/vtigercrm
  • code80team/vtigercrm
  • code80/vtigercrm
  • nilay.automatesmb/cache
  • greeshma.kk/vtigercrm
  • vijay.tilak/vtigercrm
  • Paolo.Palamini/vtigercrm
  • estevan/vtigercrm
  • mobilcmcdk/vtigercrm
  • massimiliano.vessi/vtigercrm
  • daniel.voelskow/vtigercrm
  • james1/vtigercrm
  • lokesh.s/vtigercrm
  • rdb/vtigercrm
  • neftaliyagua/vtigercrm
  • angelo.paglialonga/vtigercrm
  • webmarka/vtigercrm
  • javanile/vtigercrm
  • akshath/vtigercrm
  • Hemanth/vtigercrm
  • opencrmitalia/vtigercrm
  • direzione/vtigercrm
  • umadas306/vtigercrm
  • jd-wraptec/vtigercrm
  • felipe.camacho/vtigercrm
  • Martin.allen/vtigercrm
  • amit.r/vtigercrm
  • vicus/vtigercrm
  • dev.osmi/vtigercrm
  • laurent.guillout/vtigercrm
  • christian.blaeul/vtigercrm
  • ap.js100/vtigercrm
  • yoann.mourot/vtigercrm-temp
  • christian.cruz/vtigercrm
  • zyli/vtigercrm
  • kaushik.p/vtigercrm
  • Madhuk/vtigercrm
  • cinakzm/vtigercrm
  • raquel.martinez/vtigercrm
  • tosajibadhi/vtigercrm
  • melvin.i/vtigercrm-melvin
  • ashashingadia/vtigercrm
  • stefanwarnat/vtigercrm
  • saran.s/vtigercrm
  • eduardomozart/vtigercrm
  • Daniel.Lennartz1/vtigercrm
  • juergen.fassmann/vtigercrm
  • Michel.Ram/vtigercrm
  • vincenzo.bruno/vtigercrm
  • Hitesh.Solanki/vtigercrm
133 results
Show changes
Showing
with 419 additions and 821 deletions
......@@ -14,11 +14,18 @@
var $result ;
var $error;
function State(){
function __construct()
{
$this->success = false;
$this->result = array();
$this->error = array();
}
function State(){
// PHP4-style constructor.
// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
// In that case, call the new-style constructor to keep compatibility.
self::__construct();
}
}
......
......@@ -71,7 +71,7 @@
throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED,
"Permission to access reference type is denied ".$referenceObject->getEntityName());
}
}else if($element[$fieldName] !== NULL){
}else if(array_key_exists($fieldName, $element) && $element[$fieldName] !== NULL){
unset($element[$fieldName]);
}
}
......@@ -79,7 +79,7 @@
$meta->hasMandatoryFields($element);
$ownerFields = $meta->getOwnerFields();
if(is_array($ownerFields) && sizeof($ownerFields) >0){
if(is_array($ownerFields) && php7_sizeof($ownerFields) >0){
foreach($ownerFields as $ownerField){
if(isset($element[$ownerField]) && $element[$ownerField]!==null &&
!$meta->hasAssignPrivilege($element[$ownerField])){
......@@ -93,4 +93,4 @@
return $entity;
}
?>
\ No newline at end of file
?>
......@@ -57,7 +57,7 @@ function vtws_generateRandomAccessKey($length=10){
$accesskey = "";
$maxIndex = strlen($source);
for($i=0;$i<$length;++$i){
$accesskey = $accesskey.substr($source,rand(null,$maxIndex),1);
$accesskey = $accesskey.substr($source,rand(0,$maxIndex),1);
}
return $accesskey;
}
......@@ -117,10 +117,19 @@ function vtws_getUserWebservicesGroups($tabId,$user){
}
function vtws_getIdComponents($elementid){
$elementid = (string)$elementid;
if ($elementid && is_numeric($elementid)) return array($elementid); // during (UserId permission check)
if (!$elementid || !preg_match("/[0-9]+x[0-9]+/", $elementid)) {
throw new WebServiceException(WebServiceErrorCode::$INVALIDID,"Id specified is incorrect");
}
return explode("x",$elementid);
}
function vtws_getId($objId, $elemId){
if(is_array($elemId)){$elemId=implode(' ',$elemId);}
if(!is_numeric($objId) || !is_numeric($elemId)) {
throw new WebServiceException(WebServiceErrorCode::$INVALIDID,"Id specified is incorrect");
}
return $objId."x".$elemId;
}
......@@ -139,9 +148,10 @@ function getEmailFieldId($meta, $entityId){
function vtws_getParameter($parameterArray, $paramName,$default=null){
if (!get_magic_quotes_gpc()) {
if(is_array($parameterArray[$paramName])) {
$param = null;
if(isset($parameterArray[$paramName]) && is_array($parameterArray[$paramName])) {
$param = array_map('addslashes', $parameterArray[$paramName]);
} else {
} else if (isset($parameterArray[$paramName]) && $parameterArray[$paramName]) {
$param = addslashes($parameterArray[$paramName]);
}
} else {
......@@ -476,34 +486,33 @@ function vtws_getModuleHandlerFromId($id,$user){
}
function vtws_CreateCompanyLogoFile($fieldname) {
global $root_directory;
$uploaddir = $root_directory ."/test/logo/";
$allowedFileTypes = array("jpeg", "png", "jpg", "pjpeg" ,"x-png");
$binFile = $_FILES[$fieldname]['name'];
$fileType = $_FILES[$fieldname]['type'];
$fileSize = $_FILES[$fieldname]['size'];
$fileTypeArray = explode("/",$fileType);
$fileTypeValue = strtolower($fileTypeArray[1]);
if($fileTypeValue == '') {
$fileTypeValue = substr($binFile,strrpos($binFile, '.')+1);
}
if($fileSize != 0) {
if(in_array($fileTypeValue, $allowedFileTypes)) {
move_uploaded_file($_FILES[$fieldname]["tmp_name"],
$uploaddir.$_FILES[$fieldname]["name"]);
copy($uploaddir.$_FILES[$fieldname]["name"], $uploaddir.'application.ico');
return $binFile;
}
throw new WebServiceException(WebServiceErrorCode::$INVALIDTOKEN,
"$fieldname wrong file type given for upload");
}
throw new WebServiceException(WebServiceErrorCode::$INVALIDTOKEN,
"$fieldname file upload failed");
$fileSize = $_FILES[$fieldname]['size'];
if($fileSize != 0) {
global $root_directory;
//Support formats allowed to upload as per CRM UI.
$logoSupportedFormats = array('jpeg', 'jpg', 'png', 'gif', 'pjpeg', 'x-png');
$file_type_details = explode("/", $_FILES[$fieldname]['type']);
$filetype = $file_type_details['1'];
if(in_array($filetype, $logoSupportedFormats)) {
$uploaddir = $root_directory ."/test/logo/";
$binFile = $_FILES[$fieldname]['name'];
$saveLogo = validateImageFile($_FILES[$fieldname]);
if($saveLogo) {
move_uploaded_file($_FILES[$fieldname]["tmp_name"], $uploaddir.$binFile);
copy($uploaddir.$binFile, $uploaddir.'application.ico');
return $binFile;
}
}
throw new WebServiceException(WebServiceErrorCode::$FAILED_TO_UPDATE,
"$fieldname wrong file type given for upload");
}
throw new WebServiceException(WebServiceErrorCode::$FAILED_TO_UPDATE, "$fieldname file upload failed");
}
function vtws_getActorEntityName ($name, $idList) {
$db = PearDatabase::getInstance();
if (!is_array($idList) && count($idList) == 0) {
if (!is_array($idList) && php7_count($idList) == 0) {
return array();
}
$entity = VtigerWebserviceObject::fromName($db, $name);
......@@ -512,7 +521,7 @@ function vtws_getActorEntityName ($name, $idList) {
function vtws_getActorEntityNameById ($entityId, $idList) {
$db = PearDatabase::getInstance();
if (!is_array($idList) && count($idList) == 0) {
if (!is_array($idList) && php7_count($idList) == 0) {
return array();
}
$nameList = array();
......@@ -694,7 +703,7 @@ function vtws_getFieldfromFieldId($fieldId, $fieldObjectList){
*/
function vtws_getRelatedActivities($leadId,$accountId,$contactId,$relatedId) {
if(empty($leadId) || empty($relatedId) || (empty($accountId) && empty($contactId))){
if(empty($leadId) || empty($relatedId) || empty($contactId)){
throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED,
"Failed to move related Activities/Emails");
}
......@@ -822,110 +831,111 @@ function vtws_transferComments($sourceRecordId, $destinationRecordId) {
function vtws_transferOwnership($ownerId, $newOwnerId, $delete=true) {
$db = PearDatabase::getInstance();
//Updating the smownerid, modifiedby in vtiger_crmentity
$sql = "UPDATE vtiger_crmentity SET smownerid=?, modifiedtime = ? WHERE smownerid=? AND setype<>?";
$db->pquery($sql, array($newOwnerId, date('Y-m-d H:i:s'), $ownerId, 'ModComments'));
$sql = "update vtiger_crmentity set modifiedby=? where modifiedby=?";
$db->pquery($sql, array($newOwnerId, $ownerId));
$db->pquery('UPDATE vtiger_crmentity SET smownerid=?, modifiedtime = ? WHERE smownerid=? AND setype<>?', array($newOwnerId, date('Y-m-d H:i:s'), $ownerId, 'ModComments'));
$db->pquery('UPDATE vtiger_crmentity SET modifiedby=? WHERE modifiedby=?', array($newOwnerId, $ownerId));
//deleting from vtiger_tracker
if ($delete) {
$sql = "delete from vtiger_tracker where user_id=?";
$db->pquery($sql, array($ownerId));
}
$db->pquery('DELETE FROM vtiger_tracker WHERE user_id=?', array($ownerId));
//updating the vtiger_import_maps
$sql ="update vtiger_import_maps set assigned_user_id=? where assigned_user_id=?";
$db->pquery($sql, array($newOwnerId, $ownerId));
//delete from vtiger_homestuff
$db->pquery('DELETE FROM vtiger_homestuff WHERE userid=?', array($ownerId));
if(Vtiger_Utils::CheckTable('vtiger_customerportal_prefs')) {
$query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
$params = array($newOwnerId, 'defaultassignee', $ownerId);
$db->pquery($query, $params);
//updating the vtiger_import_maps
$db->pquery('UPDATE vtiger_import_maps SET assigned_user_id=? WHERE assigned_user_id=?', array($newOwnerId, $ownerId));
$query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey = ? AND prefvalue = ?';
$params = array($newOwnerId, 'userid', $ownerId);
if (Vtiger_Utils::CheckTable('vtiger_customerportal_prefs')) {
$query = 'UPDATE vtiger_customerportal_prefs SET prefvalue = ? WHERE prefkey IN (?, ?) AND prefvalue = ?';
$params = array($newOwnerId, 'userid', 'defaultassignee', $ownerId);
$db->pquery($query, $params);
}
//delete from vtiger_homestuff
if ($delete) {
$sql = "delete from vtiger_homestuff where userid=?";
$db->pquery($sql, array($ownerId));
}
//delete from vtiger_users to vtiger_role vtiger_table
if ($delete) {
$sql = "delete from vtiger_users2group where userid=?";
$db->pquery($sql, array($ownerId));
}
$sql = "SELECT tablename,columnname FROM vtiger_field
LEFT JOIN vtiger_fieldmodulerel ON vtiger_field.fieldid=vtiger_fieldmodulerel.fieldid
WHERE (uitype IN (?,?,?,?) OR (uitype=? AND relmodule=?)) AND columnname <> ? GROUP BY tablename,columnname ORDER BY NULL";
$result = $db->pquery($sql, array(52, 53, 77, 101, 10, 'Users', 'smcreatorid'));
$sql = "SELECT tabid,fieldname,tablename,columnname FROM vtiger_field
LEFT JOIN vtiger_fieldmodulerel ON vtiger_field.fieldid=vtiger_fieldmodulerel.fieldid
WHERE (uitype in (52,53,77,101) OR (uitype=10 AND relmodule='Users')) AND columnname <> 'smcreatorid'";
$result = $db->pquery($sql, array());
$it = new SqlResultIterator($db, $result);
$columnList = array();
foreach ($it as $row) {
$column = $row->tablename.'.'.$row->columnname;
if(!in_array($column, $columnList)) {
if (!in_array($column, $columnList)) {
$columnList[] = $column;
if($row->columnname == 'smownerid') {
$sql = "update $row->tablename set $row->columnname=? where $row->columnname=? and setype<>?";
if ($row->columnname == 'smownerid') {
$sql = "UPDATE $row->tablename set $row->columnname=? WHERE $row->columnname=? AND setype<>?";
$db->pquery($sql, array($newOwnerId, $ownerId, 'ModComments'));
} elseif ($row->tablename == 'vtiger_users' && $row->columnname == 'reports_to_id') {
$sql = "UPDATE $row->tablename SET $row->columnname = CASE WHEN id=? THEN ? ELSE ? END WHERE $row->columnname=?";
$db->pquery($sql, array($newOwnerId, '', $newOwnerId, $ownerId));
} else {
$sql = "update $row->tablename set $row->columnname=? where $row->columnname=?";
$sql = "UPDATE $row->tablename SET $row->columnname=? WHERE $row->columnname=?";
$db->pquery($sql, array($newOwnerId, $ownerId));
}
}
}
//update webforms assigned userid
$db->pquery("UPDATE vtiger_webforms SET ownerid = ? WHERE ownerid = ?", array($newOwnerId, $ownerId));
//update workflow tasks Assigned User from Deleted User to Transfer User
$newOwnerModel = Users_Record_Model::getInstanceById($newOwnerId, 'Users');
$ownerModel = Users_Record_Model::getInstanceById($ownerId, 'Users');
vtws_transferOwnershipForWorkflowTasks($ownerModel, $newOwnerModel);
vtws_updateWebformsRoundrobinUsersLists($ownerId, $newOwnerId);
vtws_updateWebformsRoundrobinUsersLists($ownerId, $newOwnerId);
//transferring non-private filters (status not 1) of deleted user to new selected user
$db->pquery('UPDATE vtiger_customview SET userid = ? WHERE userid = ? AND status != ?', array($newOwnerId, $ownerId, 1));
//transferring private shared filters of deleted user to selected user
$db->pquery('UPDATE vtiger_customview SET userid = ? WHERE userid = ? AND status = ? AND cvid IN (SELECT cvid FROM vtiger_cv2users UNION SELECT cvid FROM vtiger_cv2group UNION SELECT cvid FROM vtiger_cv2role UNION SELECT cvid FROM vtiger_cv2rs)', array($newOwnerId, $ownerId, 1));
if ($delete) {
//Delete from vtiger_users to vtiger_role vtiger_table
$db->pquery('DELETE FROM vtiger_users2group WHERE userid=?', array($ownerId));
//Mark user as deleted =1
$db->pquery('UPDATE vtiger_users SET deleted=? WHERE id=?', array(1, $ownerId));
//Change the owner for report
$db->pquery('UPDATE vtiger_report SET owner=? WHERE owner=?', array($newOwnerId, $ownerId));
//Recalculate user privelege file
RecalculateSharingRules();
}
}
function vtws_updateWebformsRoundrobinUsersLists($ownerId, $newOwnerId){
$db = PearDatabase::getInstance();
$sql = 'SELECT id,roundrobin_userid FROM vtiger_webforms;';
$result = $db->pquery($sql, array());
$numOfRows = $db->num_rows($result);
for($i=0;$i<$numOfRows;$i++){
$rowdata = $db->query_result_rowdata($result, $i);
$webformId = $rowdata['id'];
$encodedUsersList = $rowdata['roundrobin_userid'];
$encodedUsersList = str_replace("&quot;","\"",$encodedUsersList);
$usersList = json_decode($encodedUsersList,true);
if(is_array($usersList)){
if(($key = array_search($ownerId, $usersList)) !== false){
if(!in_array($newOwnerId,$usersList)){
$usersList[$key] = $newOwnerId;
}
else{
unset($usersList[$key]);
$revisedUsersList = array();
$j=0;
foreach($usersList as $uid){
$revisedUsersList[$j++] = $uid;
}
$usersList = $revisedUsersList;
}
if(count($usersList) == 0){
$db->pquery('UPDATE vtiger_webforms SET roundrobin_userid = ?,roundrobin = ? where id =?',array("--None--",0,$webformId));
}
else{
$usersList = json_encode($usersList);
$db->pquery('UPDATE vtiger_webforms SET roundrobin_userid = ? where id =?',array($usersList,$webformId));
}
}
}
}
function vtws_updateWebformsRoundrobinUsersLists($ownerId, $newOwnerId) {
$db = PearDatabase::getInstance();
$sql = 'SELECT id,roundrobin_userid FROM vtiger_webforms;';
$result = $db->pquery($sql, array());
$numOfRows = $db->num_rows($result);
for ($i = 0; $i < $numOfRows; $i++) {
$rowdata = $db->query_result_rowdata($result, $i);
$webformId = $rowdata['id'];
$encodedUsersList = $rowdata['roundrobin_userid'];
$encodedUsersList = str_replace("&quot;", "\"", $encodedUsersList);
$usersList = json_decode($encodedUsersList, true);
if (is_array($usersList)) {
if (($key = array_search($ownerId, $usersList)) !== false) {
if (!in_array($newOwnerId, $usersList)) {
$usersList[$key] = $newOwnerId;
} else {
unset($usersList[$key]);
$revisedUsersList = array();
$j = 0;
foreach ($usersList as $uid) {
$revisedUsersList[$j++] = $uid;
}
$usersList = $revisedUsersList;
}
if (php7_count($usersList) == 0) {
$db->pquery('UPDATE vtiger_webforms SET roundrobin_userid = ?,roundrobin = ? where id =?', array("--None--", 0, $webformId));
} else {
$usersList = json_encode($usersList);
$db->pquery('UPDATE vtiger_webforms SET roundrobin_userid = ? where id =?', array($usersList, $webformId));
}
}
}
}
}
function vtws_transferOwnershipForWorkflowTasks($ownerModel, $newOwnerModel) {
......@@ -961,7 +971,7 @@ function vtws_transferOwnershipForWorkflowTasks($ownerModel, $newOwnerModel) {
require_once("modules/com_vtiger_workflow/VTTaskManager.inc");
require_once 'modules/com_vtiger_workflow/tasks/'.$className.'.inc';
$unserializeTask = unserialize($task);
if(array_key_exists("field_value_mapping",$unserializeTask)) {
if(property_exists($unserializeTask, "field_value_mapping")) {
$fieldMapping = Zend_Json::decode($unserializeTask->field_value_mapping);
if (!empty($fieldMapping)) {
foreach ($fieldMapping as $key => $condition) {
......@@ -984,7 +994,7 @@ function vtws_transferOwnershipForWorkflowTasks($ownerModel, $newOwnerModel) {
}
} else {
//For VTCreateTodoTask and VTCreateEventTask
if(array_key_exists('assigned_user_id', $unserializeTask)){
if(property_exists($unserializeTask, 'assigned_user_id')){
$value = $unserializeTask->assigned_user_id;
if($value == $ownerId) {
$unserializeTask->assigned_user_id = $newOwnerId;
......@@ -1270,7 +1280,50 @@ function vtws_getCompanyId() {
function vtws_recordExists($recordId) {
$ids = vtws_getIdComponents($recordId);
return !Vtiger_Util_Helper::CheckRecordExistance($ids[1]);
return isset($ids[1]) ? !Vtiger_Util_Helper::CheckRecordExistance($ids[1]) : null;
}
function vtws_isDuplicatesAllowed($webserviceObject){
$moduleName = $webserviceObject->getEntityName();
$allowed = true;
if ($moduleName) {
$db = PearDatabase::getInstance();
$result = $db->pquery('SELECT allowduplicates FROM vtiger_tab WHERE name=?', array($moduleName));
$allowed = ($db->query_result($result, 'allowduplicates')) ? true : false;
}
return $allowed;
}
?>
\ No newline at end of file
function vtws_filedetails($fileData){
$fileDetails = array();
if(!empty($fileData)) {
$fileName = $fileData['name'];
$fileType = $fileData['type'];
$fileName = html_entity_decode($fileName, ENT_QUOTES, vglobal('default_charset'));
$filenamewithpath = $fileData['path'].$fileData['attachmentsid'].'_'.$fileData['storedname'];
$filesize = filesize($filenamewithpath);
$fileDetails['fileid'] = $fileData['attachmentsid'];
$fileDetails['filename'] = $fileName;
$fileDetails['filetype'] = $fileType;
$fileDetails['filesize'] = $filesize;
$fileDetails['filecontents'] = base64_encode(file_get_contents($filenamewithpath));
}
return $fileDetails;
}
function vtws_getAttachmentRecordId($attachmentId) {
$db = PearDatabase::getInstance();
$crmid = false;
if(!empty($attachmentId)) {
$query = "SELECT vtiger_seattachmentsrel.crmid FROM vtiger_seattachmentsrel "
. "INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_seattachmentsrel.crmid"
. " WHERE vtiger_seattachmentsrel.attachmentsid = ? AND vtiger_crmentity.deleted = ?";
$result = $db->pquery($query, array($attachmentId, 0));
if ($db->num_rows($result) > 0) {
$crmid = $db->query_result($result, 0, 'crmid');
}
}
return $crmid;
}
?>
......@@ -12,7 +12,7 @@ incState($lexer);
}
function incState($lexer){
$lexer->current_state++;
if($lexer->current_state === sizeof($lexer->mandatory_states)){
if($lexer->current_state === php7_sizeof($lexer->mandatory_states)){
$lexer->mandatory = false;
}
}
......@@ -208,7 +208,7 @@ return $this->token."";
if (preg_match($yy_global_pattern, substr($this->data, $this->index), $yymatches)) {
$yysubmatches = $yymatches;
$yymatches = array_filter($yymatches, 'strlen'); // remove empty sub-patterns
if (!count($yymatches)) {
if (!php7_count($yymatches)) {
throw new Exception('Error: lexing failed because a rule matched' .
'an empty string. Input "' . substr($this->data,
$this->index, 5) . '... state INITR');
......
......@@ -33,16 +33,19 @@ class VTQL_ParseryyToken implements ArrayAccess
return $this->_string;
}
#[\ReturnTypeWillChange]
function offsetExists($offset)
{
return isset($this->metadata[$offset]);
}
#[\ReturnTypeWillChange]
function offsetGet($offset)
{
return $this->metadata[$offset];
}
#[\ReturnTypeWillChange]
function offsetSet($offset, $value)
{
if ($offset === null) {
......@@ -52,7 +55,7 @@ class VTQL_ParseryyToken implements ArrayAccess
$this->metadata = array_merge($this->metadata, $x);
return;
}
$offset = count($this->metadata);
$offset = php7_count($this->metadata);
}
if ($value === null) {
return;
......@@ -66,6 +69,7 @@ class VTQL_ParseryyToken implements ArrayAccess
}
}
#[\ReturnTypeWillChange]
function offsetUnset($offset)
{
unset($this->metadata[$offset]);
......@@ -204,15 +208,18 @@ function buildSelectStmt($sqlDump){
$deletedQuery = $meta->getEntityDeletedQuery();
$accessControlQuery = $meta->getEntityAccessControlQuery();
$this->query = $this->query.' '.$accessControlQuery;
if($sqlDump['where_condition']){
if((sizeof($sqlDump['where_condition']['column_names']) ==
sizeof($sqlDump['where_condition']['column_values'])) &&
(sizeof($sqlDump['where_condition']['column_operators']) == sizeof($sqlDump['where_condition']['operators'])+1)){
if(isset($sqlDump['where_condition'])){
// ensure init before use
if(!isset($sqlDump['where_condition']['operators'])) $sqlDump['where_condition']['operators'] = array();
if((php7_sizeof($sqlDump['where_condition']['column_names']) ==
php7_sizeof($sqlDump['where_condition']['column_values'])) &&
(php7_sizeof($sqlDump['where_condition']['column_operators']) == php7_sizeof($sqlDump['where_condition']['operators'])+1)){
$this->query = $this->query.' WHERE (';
$i=0;
$referenceFields = $meta->getReferenceFieldDetails();
$ownerFields = $meta->getOwnerFields();
for(;$i<sizeof($sqlDump['where_condition']['column_values']);++$i){
for(;$i<php7_sizeof($sqlDump['where_condition']['column_values']);++$i){
if(!$fieldcol[$sqlDump['where_condition']['column_names'][$i]]){
throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED, "Permission to access ".$sqlDump['where_condition']['column_names'][$i]." attribute denied.");
}
......@@ -253,7 +260,7 @@ function buildSelectStmt($sqlDump){
}
$this->query = $this->query.$columnTable[$fieldcol[$whereField]].'.'.
$fieldcol[$whereField]." ".$whereOperator." ".$whereValue;
if($i <sizeof($sqlDump['where_condition']['column_values'])-1){
if($i <php7_sizeof($sqlDump['where_condition']['column_values'])-1){
$this->query = $this->query.' ';
$this->query = $this->query.$sqlDump['where_condition']['operators'][$i].' ';
}
......@@ -280,7 +287,7 @@ function buildSelectStmt($sqlDump){
$this->query = $this->query.' '.$deletedQuery;
if($sqlDump['orderby']){
if(isset($sqlDump['orderby'])){
$i=0;
$this->query = $this->query.' ORDER BY ';
foreach($sqlDump['orderby'] as $ind=>$field){
......@@ -291,14 +298,14 @@ function buildSelectStmt($sqlDump){
$this->query = $this->query.','.$columnTable[$fieldcol[$field]].".".$fieldcol[$field];
}
}
if($sqlDump['sortOrder']) {
if(isset($sqlDump['sortOrder'])) {
$this->query .= ' '.$sqlDump['sortOrder'];
}
}
if($sqlDump['limit']){
if(isset($sqlDump['limit'])){
$i=0;
$offset =false;
if(sizeof($sqlDump['limit'])>1){
if(php7_sizeof($sqlDump['limit'])>1){
$offset = true;
}
$this->query = $this->query.' LIMIT ';
......@@ -718,7 +725,7 @@ static public $yy_action = array(
if ($tokenType === 0) {
return 'End of Input';
}
if ($tokenType > 0 && $tokenType < count(self::$yyTokenName)) {
if ($tokenType > 0 && $tokenType < php7_count(self::$yyTokenName)) {
return self::$yyTokenName[$tokenType];
} else {
return "Unknown";
......@@ -760,7 +767,7 @@ static public $yy_action = array(
*/
function yy_pop_parser_stack()
{
if (!count($this->yystack)) {
if (!php7_count($this->yystack)) {
return;
}
$yytos = array_pop($this->yystack);
......@@ -967,7 +974,7 @@ static public $yy_action = array(
$i += $iLookAhead;
if ($i < 0 || $i >= self::YY_SZ_ACTTAB ||
self::$yy_lookahead[$i] != $iLookAhead) {
if (count(self::$yyFallback) && $iLookAhead < count(self::$yyFallback)
if (php7_count(self::$yyFallback) && $iLookAhead < php7_count(self::$yyFallback)
&& ($iFallback = self::$yyFallback[$iLookAhead]) != 0) {
if (self::$yyTraceFILE) {
fwrite(self::$yyTraceFILE, self::$yyTracePrompt . "FALLBACK " .
......@@ -1160,9 +1167,9 @@ $this->out['select'] = $this->yystack[$this->yyidx + -7]->minor;
if($this->yystack[$this->yyidx + -5]->minor){
$this->out['from'] = $this->yystack[$this->yyidx + -5]->minor ;
}
if(SEMI){
$this->out['semi_colon'] = SEMI;
}
//if(SEMI){
//$this->out['semi_colon'] = SEMI;
//}
if($this->out['select']){
$this->buildSelectStmt($this->out);
}
......@@ -1185,7 +1192,7 @@ $this->out['column_list'][] = 'count(*)';
#line 1191 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
#line 30 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
function yy_r7(){
if(!in_array("*", $this->out["column_list"]) && !in_array("count(*)", array_map(strtolower, $this->out["column_list"]))){
if(!in_array("*", $this->out["column_list"]) && !in_array("count(*)", array_map('strtolower', $this->out["column_list"]))){
if(!in_array("id",$this->out["column_list"])){
$this->out["column_list"][] = "id";
}
......@@ -1212,7 +1219,7 @@ $this->out['where_condition']['operators'][] = $this->yystack[$this->yyidx + 0]-
$this->out['columnDone']=true;
$this->out['where_condition']['column_names'][] = $this->yystack[$this->yyidx + -2]->minor;
if(strcmp($this->yystack[$this->yyidx + -2]->minor, 'id')===0){
$prev = $this->out['where_condition']['column_values'][sizeof($this->out['where_condition']['column_values'])-1];
$prev = $this->out['where_condition']['column_values'][php7_sizeof($this->out['where_condition']['column_values'])-1];
if(is_array($prev)){
$new = array();
foreach($prev as $ind=>$val){
......@@ -1220,21 +1227,22 @@ $val = trim($val,'\'"');
$value = vtws_getIdComponents($val);
$new[] = $value[1];
}
$this->out['where_condition']['column_values'][sizeof($this->out['where_condition']['column_values'])-1] = $new;
$this->out['where_condition']['column_values'][php7_sizeof($this->out['where_condition']['column_values'])-1] = $new;
}else{
$prev = trim($prev,'\'"');
$value = vtws_getIdComponents($prev);
if(strcasecmp($this->out['where_condition']['column_operators'][sizeof($this->out['where_condition']['column_operators'])-1],'like')===0){
if(strcasecmp($this->out['where_condition']['column_operators'][php7_sizeof($this->out['where_condition']['column_operators'])-1],'like')===0){
$value[1] = "'".$value[1]."'";
}
$this->out['where_condition']['column_values'][sizeof($this->out['where_condition']['column_values'])-1] = $value[1];
$this->out['where_condition']['column_values'][php7_sizeof($this->out['where_condition']['column_values'])-1] = $value[1];
}
}
}
#line 1240 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.php"
#line 82 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
function yy_r17(){
$length = sizeof($this->out['where_condition']['column_values']);
$this->out['where_condition']['column_values'] = isset($this->out['where_condition']['column_values']) ? $this->out['where_condition']['column_values'] : array();
$length = ($this->out['where_condition']['column_values'])? php7_sizeof($this->out['where_condition']['column_values']):0;
$pos = $length - 1;
if($pos < 0){
$pos = 0;
......@@ -1322,7 +1330,7 @@ $this->out['limit'][] = $this->yystack[$this->yyidx + 0]->minor;
#line 151 "e:\workspace\nonadmin\pkg\vtiger\extensions\Webservices\VTQL_parser.y"
function yy_r41(){
global $adb;
if(!$this->out['meta']){
if(!isset($this->out['meta'])){
$module = $this->out['moduleName'];
$handler = vtws_getModuleHandlerFromName($module,$this->user);
$objectMeta = $handler->getMeta();
......@@ -1332,12 +1340,12 @@ $fieldcol = $meta->getFieldColumnMapping();
$columns = array();
if(in_array('*', $this->out['column_list'])){
$columns = array_values($fieldcol);
}elseif( !in_array('count(*)', array_map(strtolower, $this->out['column_list']))){
}elseif( !in_array('count(*)', array_map('strtolower', $this->out['column_list']))){
foreach($this->out['column_list'] as $ind=>$field){
$columns[] = $fieldcol[$field];
}
}
if($this->out['where_condition']){
if(isset($this->out['where_condition']) && isset($this->out['where_condition']['column_names'])){
foreach($this->out['where_condition']['column_names'] as $ind=>$field){
$columns[] = $fieldcol[$field];
}
......@@ -1355,6 +1363,7 @@ array_push($tables,$tableName);
$firstTable = $objectMeta->getEntityBaseTable();
$tabNameIndex = $objectMeta->getEntityTableIndexList();
$firstIndex = $tabNameIndex[$firstTable];
if (!isset($this->out['defaultJoinConditons'])) $this->out['defaultJoinConditions'] = '';
foreach($tables as $ind=>$table){
if($firstTable!=$table){
if(!isset($tabNameIndex[$table]) && $table == "vtiger_crmentity"){
......@@ -1416,7 +1425,7 @@ if($firstTable!=$table){
//int $yysize; /* Amount to pop the stack */
$yymsp = $this->yystack[$this->yyidx];
if (self::$yyTraceFILE && $yyruleno >= 0
&& $yyruleno < count(self::$yyRuleName)) {
&& $yyruleno < php7_count(self::$yyRuleName)) {
fprintf(self::$yyTraceFILE, "%sReduce (%d) [%s].\n",
self::$yyTracePrompt, $yyruleno,
self::$yyRuleName[$yyruleno]);
......
......@@ -263,7 +263,7 @@ class VtigerActorOperation extends WebserviceEntityOperation {
foreach ($moduleFields as $fieldName=>$webserviceField) {
array_push($fields,$this->getDescribeFieldArray($webserviceField));
}
$label = ($app_strings[$this->meta->getObectIndexColumn()])? $app_strings[$this->meta->getObectIndexColumn()]:
$label = isset($app_strings[$this->meta->getObectIndexColumn()])? $app_strings[$this->meta->getObectIndexColumn()]:
$this->meta->getObectIndexColumn();
$this->moduleFields = $fields;
}
......@@ -276,7 +276,9 @@ class VtigerActorOperation extends WebserviceEntityOperation {
if(isset($app_strings[$fieldLabel])){
$fieldLabel = $app_strings[$fieldLabel];
}
if(strcasecmp($webserviceField->getFieldName(),$this->meta->getObectIndexColumn()) === 0){
$fieldName = $webserviceField->getFieldName();
$fieldColumn = $this->meta->getObectIndexColumn();
if($fieldColumn && strcasecmp($fieldName, $fieldColumn) === 0){
return $this->getIdField($fieldLabel);
}
......@@ -334,4 +336,4 @@ class VtigerActorOperation extends WebserviceEntityOperation {
}
}
?>
\ No newline at end of file
?>
......@@ -13,7 +13,8 @@ class VtigerCRMActorMeta extends EntityMeta {
protected static $fieldTypeMapping = array();
protected static $referenceTypeMapping = array();
function VtigerCRMActorMeta($tableName,$webserviceObject,$adb,$user){
function __construct($tableName,$webserviceObject,$adb,$user)
{
parent::__construct($webserviceObject,$user);
$this->baseTable = $tableName;
$this->idColumn = null;
......@@ -23,6 +24,12 @@ class VtigerCRMActorMeta extends EntityMeta {
$this->tableIndexList = null;
$this->defaultTableList = array();
}
function VtigerCRMActorMeta($tableName,$webserviceObject,$adb,$user){
// PHP4-style constructor.
// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
// In that case, call the new-style constructor to keep compatibility.
self::__construct($tableName,$webserviceObject,$adb,$user);
}
public function getIdColumn() {
if($this->idColumn === null) {
......@@ -98,7 +105,7 @@ class VtigerCRMActorMeta extends EntityMeta {
$fieldType = $this->getTypeOfDataForType($dbField->type);
}
$typeOfData = null;
if(($dbField->not_null && !$dbField->primary_key) || $dbField->unique_key == 1){
if(($dbField->not_null && !$dbField->primary_key) || (isset($dbField->unique_key) && $dbField->unique_key == 1)) {
$typeOfData = $fieldType.'~M';
}else{
$typeOfData = $fieldType.'~O';
......
......@@ -13,8 +13,8 @@ class VtigerCRMObject{
private $moduleName ;
private $moduleId ;
private $instance ;
function VtigerCRMObject($moduleCredential, $isId=false){
function __construct($moduleCredential, $isId=false)
{
if($isId){
$this->moduleId = $moduleCredential;
......@@ -26,6 +26,12 @@ class VtigerCRMObject{
$this->instance = null;
$this->getInstance();
}
function VtigerCRMObject($moduleCredential, $isId=false){
// PHP4-style constructor.
// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
// In that case, call the new-style constructor to keep compatibility.
self::__construct($moduleCredential, $isId);
}
public function getModuleName(){
return $this->moduleName;
......@@ -179,7 +185,7 @@ class VtigerCRMObject{
global $adb;
$error = false;
$adb->startTransaction();
DeleteEntity($this->getTabName(), $this->getTabName(), $this->instance, $id,$returnid);
DeleteEntity($this->getTabName(), $this->getTabName(), $this->instance, $id,"");
$error = $adb->hasFailedTransaction();
$adb->completeTransaction();
return !$error;
......@@ -193,7 +199,7 @@ class VtigerCRMObject{
global $adb;
$exists = false;
$sql = "select * from vtiger_crmentity where crmid=? and deleted=0";
$sql = "select 1 from vtiger_crmentity where crmid=? and deleted=0";
$result = $adb->pquery($sql , array($id));
if($result != null && isset($result)){
if($adb->num_rows($result)>0){
......@@ -207,7 +213,7 @@ class VtigerCRMObject{
global $adb;
$seType = null;
$sql = "select * from vtiger_crmentity where crmid=? and deleted=0";
$sql = "select setype from vtiger_crmentity where crmid=? and deleted=0";
$result = $adb->pquery($sql , array($id));
if($result != null && isset($result)){
if($adb->num_rows($result)>0){
......
......@@ -20,8 +20,10 @@ class VtigerCRMObjectMeta extends EntityMeta {
private $hasWriteAccess;//Edit Access
private $hasDeleteAccess;
private $assignUsers;
private $allowDuplicates;
function VtigerCRMObjectMeta($webserviceObject,$user){
function __construct($webserviceObject,$user)
{
parent::__construct($webserviceObject,$user);
......@@ -38,6 +40,7 @@ class VtigerCRMObjectMeta extends EntityMeta {
$this->hasCreateAccess = false;
$this->hasWriteAccess = false;
$this->hasDeleteAccess = false;
$this->allowDuplicates = null;
$instance = vtws_getModuleInstance($this->webserviceObject);
$this->idColumn = $instance->tab_name_index[$instance->table_name];
$this->baseTable = $instance->table_name;
......@@ -50,6 +53,12 @@ class VtigerCRMObjectMeta extends EntityMeta {
}
$this->tabId = null;
}
function VtigerCRMObjectMeta($webserviceObject,$user){
// PHP4-style constructor.
// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
// In that case, call the new-style constructor to keep compatibility.
self::__construct($webserviceObject,$user);
}
/**
* returns tabid of the current object.
......@@ -216,11 +225,12 @@ class VtigerCRMObjectMeta extends EntityMeta {
function hasPermission($operation,$webserviceId){
$idComponents = vtws_getIdComponents($webserviceId);
$id=$idComponents[1];
$permitted = isPermitted($this->getTabName(),$operation,$id);
if(strcmp($permitted,"yes")===0){
return true;
$id=$idComponents ? array_pop($idComponents):null;
if ($id) {
$permitted = isPermitted($this->getTabName(),$operation,$id);
if(strcmp($permitted,"yes")===0){
return true;
}
}
return false;
}
......@@ -298,6 +308,11 @@ class VtigerCRMObjectMeta extends EntityMeta {
if (strcasecmp($webserviceField->getFieldDataType(), 'file') !== 0) {
$this->fieldColumnMapping[$fieldName] = $webserviceField->getColumnName();
}
} else if($this->getEntityName() == "Users") {
$restrictedFields = array('user_password', 'confirm_password', 'accesskey');
if(!in_array($fieldName, $restrictedFields)) {
$this->fieldColumnMapping[$fieldName] = $webserviceField->getColumnName();
}
} else {
$this->fieldColumnMapping[$fieldName] = $webserviceField->getColumnName();
}
......@@ -359,7 +374,7 @@ class VtigerCRMObjectMeta extends EntityMeta {
require_once('modules/CustomView/CustomView.php');
$current_user = vtws_preserveGlobal('current_user',$this->user);
$theme = vtws_preserveGlobal('theme',$this->user->theme);
$theme = vtws_preserveGlobal('theme', isset($this->user->theme) ? $this->user->theme : "");
$default_language = VTWS_PreserveGlobal::getGlobal('default_language');
global $current_language;
if(empty($current_language)) $current_language = $default_language;
......@@ -383,7 +398,7 @@ class VtigerCRMObjectMeta extends EntityMeta {
$heirarchyUsers = get_user_array(false,"ACTIVE",$this->user->id);
$groupUsers = vtws_getUsersInTheSameGroup($this->user->id);
$this->assignUsers = $heirarchyUsers+$groupUsers;
$this->assignUsers = $heirarchyUsers + $groupUsers;
$this->assign = true;
}
......@@ -399,7 +414,7 @@ class VtigerCRMObjectMeta extends EntityMeta {
}else{
$profileList = getCurrentUserProfileList();
if (count($profileList) > 0) {
if (php7_count($profileList) > 0) {
$sql = "SELECT vtiger_field.*, vtiger_profile2field.readonly
FROM vtiger_field
INNER JOIN vtiger_profile2field
......@@ -408,7 +423,7 @@ class VtigerCRMObjectMeta extends EntityMeta {
ON vtiger_def_org_field.fieldid = vtiger_field.fieldid
WHERE vtiger_field.tabid =? AND vtiger_profile2field.visible = 0
AND vtiger_profile2field.profileid IN (". generateQuestionMarks($profileList) .")
AND vtiger_def_org_field.visible = 0 and vtiger_field.block in (".generateQuestionMarks($block).") and vtiger_field.displaytype in (1,2,3,4,5) and vtiger_field.presence in (0,2) group by columnname";
AND vtiger_def_org_field.visible = 0 and vtiger_field.block in (".generateQuestionMarks($block).") and vtiger_field.displaytype in (1,2,3,4,5,6) and vtiger_field.presence in (0,2) group by columnname";
$params = array($tabid, $profileList, $block);
} else {
$sql = "SELECT vtiger_field.*, vtiger_profile2field.readonly
......@@ -419,7 +434,7 @@ class VtigerCRMObjectMeta extends EntityMeta {
ON vtiger_def_org_field.fieldid = vtiger_field.fieldid
WHERE vtiger_field.tabid=?
AND vtiger_profile2field.visible = 0
AND vtiger_def_org_field.visible = 0 and vtiger_field.block in (".generateQuestionMarks($block).") and vtiger_field.displaytype in (1,2,3,4,5) and vtiger_field.presence in (0,2) group by columnname";
AND vtiger_def_org_field.visible = 0 and vtiger_field.block in (".generateQuestionMarks($block).") and vtiger_field.displaytype in (1,2,3,4,5,6) and vtiger_field.presence in (0,2) group by columnname";
$params = array($tabid, $block);
}
}
......@@ -553,5 +568,12 @@ class VtigerCRMObjectMeta extends EntityMeta {
return true;
}
public function isDuplicatesAllowed() {
if (is_null($this->allowDuplicates) || $this->allowDuplicates === null) {
$this->allowDuplicates = vtws_isDuplicatesAllowed($this->webserviceObject);
}
return $this->allowDuplicates;
}
}
?>
\ No newline at end of file
?>
......@@ -13,11 +13,19 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
protected $isEntity = true;
protected $partialDescribeFields = null;
public function VtigerModuleOperation($webserviceObject,$user,$adb,$log){
public function __construct($webserviceObject,$user,$adb,$log)
{
parent::__construct($webserviceObject,$user,$adb,$log);
$this->meta = $this->getMetaInstance();
$this->tabId = $this->meta->getTabId();
}
public function VtigerModuleOperation($webserviceObject,$user,$adb,$log){
// PHP4-style constructor.
// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
// In that case, call the new-style constructor to keep compatibility.
self::__construct($webserviceObject,$user,$adb,$log);
}
protected function getMetaInstance(){
if(empty(WebserviceEntityOperation::$metaCache[$this->webserviceObject->getEntityName()][$this->user->id])){
......@@ -73,6 +81,7 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
}
public function relatedIds($id, $relatedModule, $relatedLabel, $relatedHandler=null) {
global $adb;
$ids = vtws_getIdComponents($id);
$sourceModule = $this->webserviceObject->getEntityName();
global $currentModule;
......@@ -174,6 +183,7 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
$meta = $parser->getObjectMetaData();
$this->pearDB->startTransaction();
$result = $this->pearDB->pquery($mysql_query, array());
$tableIdColumn = $meta->getIdColumn();
$error = $this->pearDB->hasFailedTransaction();
$this->pearDB->completeTransaction();
......@@ -187,13 +197,22 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
$output = array();
for($i=0; $i<$noofrows; $i++){
$row = $this->pearDB->fetchByAssoc($result,$i);
if(!$meta->hasPermission(EntityMeta::$RETRIEVE,$row["crmid"])){
if(!isset($row[$tableIdColumn]) || !$meta->hasPermission(EntityMeta::$RETRIEVE,$row[$tableIdColumn])){
continue;
}
$output[] = DataTransform::sanitizeDataWithColumn($row,$meta);
$output[$row[$tableIdColumn]] = DataTransform::sanitizeDataWithColumn($row,$meta);
}
return $output;
$newOutput = array();
if(php7_count($output)) {
//Added check if tags was requested or not
if(stripos($mysql_query, $meta->getEntityBaseTable().'.tags') !== false) $tags = Vtiger_Tag_Model::getAllAccessibleTags(array_keys($output));
foreach($output as $id => $row1) {
if(!empty($tags[$id])) $output[$id]['tags'] = $tags[$id];
$newOutput[] = $output[$id];
}
}
return $newOutput;
}
public function describe($elementType){
......@@ -206,9 +225,17 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
$deleteable = $this->meta->hasDeleteAccess();
$retrieveable = $this->meta->hasReadAccess();
$fields = $this->getModuleFields();
return array("label"=>$label,"name"=>$elementType,"createable"=>$createable,"updateable"=>$updateable,
"deleteable"=>$deleteable,"retrieveable"=>$retrieveable,"fields"=>$fields,
"idPrefix"=>$this->meta->getEntityId(),'isEntity'=>$this->isEntity,'labelFields'=>$this->meta->getNameFields());
return array( 'label' => $label,
'name' => $elementType,
'createable' => $createable,
'updateable' => $updateable,
'deleteable' => $deleteable,
'retrieveable' => $retrieveable,
'fields' => $fields,
'idPrefix' => $this->meta->getEntityId(),
'isEntity' => $this->isEntity,
'allowDuplicates'=> $this->meta->isDuplicatesAllowed(),
'labelFields' => $this->meta->getNameFields());
}
public function describePartial($elementType, $fields=null) {
......@@ -253,9 +280,13 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
}
$editable = $this->isEditable($webserviceField);
$describeArray = array('name'=>$webserviceField->getFieldName(),'label'=>$fieldLabel,'mandatory'=>
$webserviceField->isMandatory(),'type'=>$typeDetails,'nullable'=>$webserviceField->isNullable(),
"editable"=>$editable);
$describeArray = array( 'name' => $webserviceField->getFieldName(),
'label' => $fieldLabel,
'mandatory' => $webserviceField->isMandatory(),
'type' => $typeDetails,
'isunique' => $webserviceField->isUnique(),
'nullable' => $webserviceField->isNullable(),
'editable' => $editable);
if($webserviceField->hasDefault()){
$describeArray['default'] = $webserviceField->getDefault();
}
......@@ -270,6 +301,34 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
$moduleFields = $this->meta->getModuleFields();
return $this->getDescribeFieldArray($moduleFields[$fieldName]);
}
/**
* Function to get the file content
* @param type $id
* @return type
* @throws WebServiceException
*/
public function file_retrieve($crmid, $elementType, $attachmentId=false){
$ids = vtws_getIdComponents($crmid);
$crmid = $ids[1];
$recordModel = Vtiger_Record_Model::getInstanceById($crmid, $elementType);
if($attachmentId) {
$attachmentDetails = $recordModel->getFileDetails($attachmentId);
} else {
$attachmentDetails = $recordModel->getFileDetails();
}
$fileDetails = array();
if (!empty ($attachmentDetails)) {
if(is_array(current(($attachmentDetails)))) {
foreach ($attachmentDetails as $key => $attachment) {
$fileDetails[$key] = vtws_filedetails($attachment);
}
} else if(is_array($attachmentDetails)){
$fileDetails[] = vtws_filedetails($attachmentDetails);
}
}
return $fileDetails;
}
}
?>
......@@ -119,7 +119,7 @@ class VtigerProductOperation extends VtigerModuleOperation {
$ids = vtws_getIdComponents($element['currency_id']);
//Import will be sending currency id not in webservice format .
//So we are taking 0th index as value
if (count($ids) == 1) {
if (php7_count($ids) == 1) {
$curId = $ids[0];
} else {
$curId = $ids[1];
......
......@@ -15,7 +15,8 @@ class VtigerWebserviceObject{
private $handlerPath;
private $handlerClass;
private function VtigerWebserviceObject($entityId,$entityName,$handler_path,$handler_class){
private function __construct($entityId,$entityName,$handler_path,$handler_class)
{
$this->id = $entityId;
$this->name = $entityName;
// Quick Fix to override default Actor class & path (good to update DB itself)
......@@ -28,6 +29,13 @@ class VtigerWebserviceObject{
$this->handlerClass = $handler_class;
}
private function VtigerWebserviceObject($entityId,$entityName,$handler_path,$handler_class){
// PHP4-style constructor.
// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
// In that case, call the new-style constructor to keep compatibility.
self::__construct($entityId,$entityName,$handler_path,$handler_class);
}
// Cache variables to enable result re-use
private static $_fromNameCache = array();
......@@ -37,7 +45,7 @@ class VtigerWebserviceObject{
// If the information not available in cache?
if(!isset(self::$_fromNameCache[$entityName])) {
$cacheLength = count(self::$_fromNameCache);
$cacheLength = php7_count(self::$_fromNameCache);
$result = null;
if ($cacheLength == 0) {
......@@ -84,7 +92,7 @@ class VtigerWebserviceObject{
}
}
$rowData = self::$_fromIdCache[$entityId];
$rowData = isset(self::$_fromIdCache[$entityId]) ? self::$_fromIdCache[$entityId] : '';
if($rowData) {
return new VtigerWebserviceObject($rowData['id'],$rowData['name'],
......@@ -121,4 +129,4 @@ class VtigerWebserviceObject{
}
}
?>
\ No newline at end of file
?>
......@@ -13,11 +13,17 @@
public $code;
public $message;
function WebServiceException($errCode,$msg){
function __construct($errCode,$msg)
{
$this->code = $errCode;
$this->message = $msg;
}
function WebServiceException($errCode,$msg){
// PHP4-style constructor.
// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
// In that case, call the new-style constructor to keep compatibility.
self::__construct($errCode,$msg);
}
}
......
......@@ -42,6 +42,8 @@
public static $POTENTIAL_RELATED_UPDATE_FAILED = "POTENTIAL_RELATEDLIST_UPDATE_FAILED";
public static $FAILED_TO_CREATE = "FAILED_TO_CREATE";
public static $INACTIVECURRENCY = "CURRENCY_INACTIVE";
public static $PASSWORDNOTSTRONG = "PASSWORD_NOT_STRONG";
public static $FAILED_TO_UPDATE = "FAILED_TO_UPDATE";
}
?>
......@@ -21,12 +21,19 @@ abstract class WebserviceEntityOperation{
protected static $metaCache = array();
protected function WebserviceEntityOperation($webserviceObject,$user,$adb,$log){
protected function __construct($webserviceObject,$user,$adb,$log)
{
$this->user = $user;
$this->log = $log;
$this->webserviceObject = $webserviceObject;
$this->pearDB = $adb;
}
protected function WebserviceEntityOperation($webserviceObject,$user,$adb,$log){
// PHP4-style constructor.
// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
// In that case, call the new-style constructor to keep compatibility.
self::__construct($webserviceObject,$user,$adb,$log);
}
public function create($elementType,$element){
throw new WebServiceException(WebServiceErrorCode::$OPERATIONNOTSUPPORTED,
......@@ -76,7 +83,7 @@ abstract class WebserviceEntityOperation{
break;
case 'multipicklist':
case 'picklist': $typeDetails["picklistValues"] = $webserviceField->getPicklistDetails($webserviceField);
$typeDetails['defaultValue'] = $typeDetails["picklistValues"][0]['value'];
$typeDetails['defaultValue'] = !empty($typeDetails["picklistValues"]) ? $typeDetails["picklistValues"][0]['value'] : null;
break;
case 'file': $maxUploadSize = 0;
$maxUploadSize = ini_get('upload_max_filesize');
......@@ -124,4 +131,4 @@ abstract class WebserviceEntityOperation{
}
?>
\ No newline at end of file
?>
......@@ -11,6 +11,7 @@
require_once 'includes/runtime/Cache.php';
require_once 'vtlib/Vtiger/Runtime.php';
#[\AllowDynamicProperties]
class WebserviceField{
private $fieldId;
private $uitype;
......@@ -46,28 +47,32 @@ class WebserviceField{
private $genericUIType = 10;
private $readOnly = 0;
private $isunique = 0;
public $parentReferenceField; //To avoid undefined property warning.
private function __construct($adb,$row){
$this->uitype = $row['uitype'];
$this->blockId = $row['block'];
$this->uitype = isset($row['uitype'])? $row['uitype'] : 0;
$this->blockId = isset($row['block'])? $row['block'] : 0;
$this->blockName = null;
$this->tableName = $row['tablename'];
$this->columnName = $row['columnname'];
$this->fieldName = $row['fieldname'];
$this->fieldLabel = $row['fieldlabel'];
$this->displayType = $row['displaytype'];
$this->massEditable = ($row['masseditable'] === '1')? true: false;
$typeOfData = $row['typeofdata'];
$this->presence = $row['presence'];
$this->tableName = isset($row['tablename'])? $row['tablename'] : null;
$this->columnName = isset($row['columnname'])? $row['columnname'] : null;
$this->fieldName = isset($row['fieldname'])? $row['fieldname'] : null;
$this->fieldLabel = isset($row['fieldlabel'])? $row['fieldlabel'] : null;
$this->displayType = isset($row['displaytype'])? $row['displaytype'] : null;
$this->massEditable = (isset($row['masseditable']) && $row['masseditable'] === '1')? true: false;
$this->presence = isset($row['presence'])? $row['presence'] : null;
$this->isunique = isset($row['isunique']) && $row['isunique'] ? true : false;
$typeOfData = isset($row['typeofdata'])? $row['typeofdata'] : null;
$this->typeOfData = $typeOfData;
$typeOfData = explode("~",$typeOfData);
$this->mandatory = ($typeOfData[1] == 'M')? true: false;
$typeOfData = explode("~",$typeOfData ? $typeOfData : "");
$this->mandatory = (php7_count($typeOfData) > 1 && $typeOfData[1] == 'M')? true: false;
if($this->uitype == 4){
$this->mandatory = false;
}
$this->fieldType = $typeOfData[0];
$this->tabid = $row['tabid'];
$this->fieldId = $row['fieldid'];
$this->tabid = isset($row['tabid'])? $row['tabid']: 0;
$this->fieldId = isset($row['fieldid'])? $row['fieldid'] : 0;
$this->pearDB = $adb;
$this->fieldDataType = null;
$this->dataFromMeta = false;
......@@ -118,6 +123,10 @@ class WebserviceField{
return $this->displayType;
}
public function isUnique(){
return $this->isunique;
}
public function getMassEditable(){
return $this->massEditable;
}
......@@ -252,7 +261,7 @@ class WebserviceField{
$referenceTypes = array();
if($this->getUIType() != $this->genericUIType){
$sql = "select type from vtiger_ws_referencetype where fieldtypeid=?";
$params = array($fieldTypeData['fieldtypeid']);
$params = array(isset($fieldTypeData['fieldtypeid'])? $fieldTypeData['fieldtypeid'] : 0);
}else{
$sql = 'SELECT relmodule AS type FROM vtiger_fieldmodulerel WHERE fieldid=? ORDER BY sequence ASC';
$params = array($this->getFieldId());
......@@ -330,6 +339,7 @@ class WebserviceField{
function getPicklistDetails(){
$cache = Vtiger_Cache::getInstance();
$fieldName = $this->getFieldName();
if($cache->getPicklistDetails($this->getTabId(),$this->getFieldName())){
return $cache->getPicklistDetails($this->getTabId(),$this->getFieldName());
} else {
......@@ -340,7 +350,26 @@ class WebserviceField{
foreach ($allRegions as $regionId => $regionDetails) {
$picklistDetails[] = array('value' => $regionId, 'label' => $regionDetails['name']);
}
} else {
}elseif ($fieldName == 'defaultlandingpage') {
$picklistDetails = array();
$presence = array(0);
$restrictedModules = array('Webmails', 'Emails', 'Integration', 'Dashboard','ModComments');
$query = 'SELECT name, tablabel, tabid FROM vtiger_tab WHERE presence IN (' . generateQuestionMarks($presence) . ') AND isentitytype = ? AND name NOT IN (' . generateQuestionMarks($restrictedModules) . ')';
$result = $this->pearDB->pquery($query, array($presence, '1', $restrictedModules));
$numOfRows = $this->pearDB->num_rows($result);
$picklistDetails[] = array('value' => 'Home', 'label' => vtranslate('Home', 'Home'));
for ($i = 0; $i < $numOfRows; $i++) {
$moduleName = $this->pearDB->query_result($result, $i, 'name');
// check the module access permission, if user has permission then show it in default module list
if (vtlib_isModuleActive($moduleName)) {
$moduleLabel = $this->pearDB->query_result($result, $i, 'tablabel');
$picklistDetails[] = array('value' => $moduleName, 'label' => vtranslate($moduleLabel, $moduleName));
}
}
} else {
$hardCodedPickListNames = array('hdntaxtype','email_flag');
$hardCodedPickListValues = array('hdntaxtype'=> array( array('label' => 'Individual', 'value' => 'individual'),
array('label' => 'Group', 'value' => 'group')),
......@@ -372,7 +401,7 @@ class WebserviceField{
if ($moduleName == 'Events') $moduleName = 'Calendar';
if($numRows == 0){
$sql = "select * from vtiger_$fieldName";
$sql = "SELECT * FROM vtiger_$fieldName ORDER BY sortorderid";
$result = $this->pearDB->pquery($sql,array());
$numRows = $this->pearDB->num_rows($result);
for($i=0;$i<$numRows;++$i){
......@@ -386,7 +415,7 @@ class WebserviceField{
}else{
$user = VTWS_PreserveGlobal::getGlobal('current_user');
$details = getPickListValues($fieldName,$user->roleid);
for($i=0;$i<sizeof($details);++$i){
for($i=0;$i<php7_sizeof($details);++$i){
$elem = array();
$picklistValue = decode_html($details[$i]);
$elem["label"] = getTranslatedString($picklistValue, $moduleName, $language);
......@@ -403,4 +432,4 @@ class WebserviceField{
}
?>
\ No newline at end of file
?>
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Crypt.php 25024 2012-07-30 15:08:15Z rob $
*/
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt
{
const TYPE_OPENSSL = 'openssl';
const TYPE_HASH = 'hash';
const TYPE_MHASH = 'mhash';
protected static $_type = null;
/**
* @var array
*/
protected static $_supportedAlgosOpenssl = array(
'md2',
'md4',
'mdc2',
'rmd160',
'sha',
'sha1',
'sha224',
'sha256',
'sha384',
'sha512'
);
/**
* @var array
*/
protected static $_supportedAlgosMhash = array(
'adler32',
'crc32',
'crc32b',
'gost',
'haval128',
'haval160',
'haval192',
'haval256',
'md4',
'md5',
'ripemd160',
'sha1',
'sha256',
'tiger',
'tiger128',
'tiger160'
);
/**
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return unknown
*/
public static function hash($algorithm, $data, $binaryOutput = false)
{
$algorithm = strtolower($algorithm);
if (function_exists($algorithm)) {
return $algorithm($data, $binaryOutput);
}
self::_detectHashSupport($algorithm);
$supportedMethod = '_digest' . ucfirst(self::$_type);
$result = self::$supportedMethod($algorithm, $data, $binaryOutput);
return $result;
}
/**
* @param string $algorithm
* @throws Zend_Crypt_Exception
*/
protected static function _detectHashSupport($algorithm)
{
if (function_exists('hash')) {
self::$_type = self::TYPE_HASH;
if (in_array($algorithm, hash_algos())) {
return;
}
}
if (function_exists('mhash')) {
self::$_type = self::TYPE_MHASH;
if (in_array($algorithm, self::$_supportedAlgosMhash)) {
return;
}
}
if (function_exists('openssl_digest')) {
if ($algorithm == 'ripemd160') {
$algorithm = 'rmd160';
}
self::$_type = self::TYPE_OPENSSL;
if (in_array($algorithm, self::$_supportedAlgosOpenssl)) {
return;
}
}
/**
* @see Zend_Crypt_Exception
*/
require_once 'Zend/Crypt/Exception.php';
throw new Zend_Crypt_Exception('\'' . $algorithm . '\' is not supported by any available extension or native function');
}
/**
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return string
*/
protected static function _digestHash($algorithm, $data, $binaryOutput)
{
return hash($algorithm, $data, $binaryOutput);
}
/**
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return string
*/
protected static function _digestMhash($algorithm, $data, $binaryOutput)
{
$constant = constant('MHASH_' . strtoupper($algorithm));
$binary = mhash($constant, $data);
if ($binaryOutput) {
return $binary;
}
return bin2hex($binary);
}
/**
* @param string $algorithm
* @param string $data
* @param bool $binaryOutput
* @return string
*/
protected static function _digestOpenssl($algorithm, $data, $binaryOutput)
{
if ($algorithm == 'ripemd160') {
$algorithm = 'rmd160';
}
return openssl_digest($data, $algorithm, $binaryOutput);
}
}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage DiffieHellman
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: DiffieHellman.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* PHP implementation of the Diffie-Hellman public key encryption algorithm.
* Allows two unassociated parties to establish a joint shared secret key
* to be used in encrypting subsequent communications.
*
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_DiffieHellman
{
/**
* Static flag to select whether to use PHP5.3's openssl extension
* if available.
*
* @var boolean
*/
public static $useOpenssl = true;
/**
* Default large prime number; required by the algorithm.
*
* @var string
*/
private $_prime = null;
/**
* The default generator number. This number must be greater than 0 but
* less than the prime number set.
*
* @var string
*/
private $_generator = null;
/**
* A private number set by the local user. It's optional and will
* be generated if not set.
*
* @var string
*/
private $_privateKey = null;
/**
* BigInteger support object courtesy of Zend_Crypt_Math
*
* @var Zend_Crypt_Math_BigInteger
*/
private $_math = null;
/**
* The public key generated by this instance after calling generateKeys().
*
* @var string
*/
private $_publicKey = null;
/**
* The shared secret key resulting from a completed Diffie Hellman
* exchange
*
* @var string
*/
private $_secretKey = null;
/**
* Constants
*/
const BINARY = 'binary';
const NUMBER = 'number';
const BTWOC = 'btwoc';
/**
* Constructor; if set construct the object using the parameter array to
* set values for Prime, Generator and Private.
* If a Private Key is not set, one will be generated at random.
*
* @param string $prime
* @param string $generator
* @param string $privateKey
* @param string $privateKeyType
* @return void
*/
public function __construct($prime, $generator, $privateKey = null, $privateKeyType = self::NUMBER)
{
$this->setPrime($prime);
$this->setGenerator($generator);
if ($privateKey !== null) {
$this->setPrivateKey($privateKey, $privateKeyType);
}
$this->setBigIntegerMath();
}
/**
* Generate own public key. If a private number has not already been
* set, one will be generated at this stage.
*
* @return Zend_Crypt_DiffieHellman
*/
public function generateKeys()
{
if (function_exists('openssl_dh_compute_key') && self::$useOpenssl !== false) {
$details = array();
$details['p'] = $this->getPrime();
$details['g'] = $this->getGenerator();
if ($this->hasPrivateKey()) {
$details['priv_key'] = $this->getPrivateKey();
}
$opensslKeyResource = openssl_pkey_new( array('dh' => $details) );
$data = openssl_pkey_get_details($opensslKeyResource);
$this->setPrivateKey($data['dh']['priv_key'], self::BINARY);
$this->setPublicKey($data['dh']['pub_key'], self::BINARY);
} else {
// Private key is lazy generated in the absence of PHP 5.3's ext/openssl
$publicKey = $this->_math->powmod($this->getGenerator(), $this->getPrivateKey(), $this->getPrime());
$this->setPublicKey($publicKey);
}
return $this;
}
/**
* Setter for the value of the public number
*
* @param string $number
* @param string $type
* @return Zend_Crypt_DiffieHellman
*/
public function setPublicKey($number, $type = self::NUMBER)
{
if ($type == self::BINARY) {
$number = $this->_math->fromBinary($number);
}
if (!preg_match("/^\d+$/", $number)) {
require_once('Zend/Crypt/DiffieHellman/Exception.php');
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
}
$this->_publicKey = (string) $number;
return $this;
}
/**
* Returns own public key for communication to the second party to this
* transaction.
*
* @param string $type
* @return string
*/
public function getPublicKey($type = self::NUMBER)
{
if ($this->_publicKey === null) {
require_once 'Zend/Crypt/DiffieHellman/Exception.php';
throw new Zend_Crypt_DiffieHellman_Exception('A public key has not yet been generated using a prior call to generateKeys()');
}
if ($type == self::BINARY) {
return $this->_math->toBinary($this->_publicKey);
} elseif ($type == self::BTWOC) {
return $this->_math->btwoc($this->_math->toBinary($this->_publicKey));
}
return $this->_publicKey;
}
/**
* Compute the shared secret key based on the public key received from the
* the second party to this transaction. This should agree to the secret
* key the second party computes on our own public key.
* Once in agreement, the key is known to only to both parties.
* By default, the function expects the public key to be in binary form
* which is the typical format when being transmitted.
*
* If you need the binary form of the shared secret key, call
* getSharedSecretKey() with the optional parameter for Binary output.
*
* @param string $publicKey
* @param string $type
* @return mixed
*/
public function computeSecretKey($publicKey, $type = self::NUMBER, $output = self::NUMBER)
{
if ($type == self::BINARY) {
$publicKey = $this->_math->fromBinary($publicKey);
}
if (!preg_match("/^\d+$/", $publicKey)) {
require_once('Zend/Crypt/DiffieHellman/Exception.php');
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
}
if (function_exists('openssl_dh_compute_key') && self::$useOpenssl !== false) {
$this->_secretKey = openssl_dh_compute_key($publicKey, $this->getPublicKey());
} else {
$this->_secretKey = $this->_math->powmod($publicKey, $this->getPrivateKey(), $this->getPrime());
}
return $this->getSharedSecretKey($output);
}
/**
* Return the computed shared secret key from the DiffieHellman transaction
*
* @param string $type
* @return string
*/
public function getSharedSecretKey($type = self::NUMBER)
{
if (!isset($this->_secretKey)) {
require_once('Zend/Crypt/DiffieHellman/Exception.php');
throw new Zend_Crypt_DiffieHellman_Exception('A secret key has not yet been computed; call computeSecretKey()');
}
if ($type == self::BINARY) {
return $this->_math->toBinary($this->_secretKey);
} elseif ($type == self::BTWOC) {
return $this->_math->btwoc($this->_math->toBinary($this->_secretKey));
}
return $this->_secretKey;
}
/**
* Setter for the value of the prime number
*
* @param string $number
* @return Zend_Crypt_DiffieHellman
*/
public function setPrime($number)
{
if (!preg_match("/^\d+$/", $number) || $number < 11) {
require_once('Zend/Crypt/DiffieHellman/Exception.php');
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number or too small: should be a large natural number prime');
}
$this->_prime = (string) $number;
return $this;
}
/**
* Getter for the value of the prime number
*
* @return string
*/
public function getPrime()
{
if (!isset($this->_prime)) {
require_once('Zend/Crypt/DiffieHellman/Exception.php');
throw new Zend_Crypt_DiffieHellman_Exception('No prime number has been set');
}
return $this->_prime;
}
/**
* Setter for the value of the generator number
*
* @param string $number
* @return Zend_Crypt_DiffieHellman
*/
public function setGenerator($number)
{
if (!preg_match("/^\d+$/", $number) || $number < 2) {
require_once('Zend/Crypt/DiffieHellman/Exception.php');
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number greater than 1');
}
$this->_generator = (string) $number;
return $this;
}
/**
* Getter for the value of the generator number
*
* @return string
*/
public function getGenerator()
{
if (!isset($this->_generator)) {
require_once('Zend/Crypt/DiffieHellman/Exception.php');
throw new Zend_Crypt_DiffieHellman_Exception('No generator number has been set');
}
return $this->_generator;
}
/**
* Setter for the value of the private number
*
* @param string $number
* @param string $type
* @return Zend_Crypt_DiffieHellman
*/
public function setPrivateKey($number, $type = self::NUMBER)
{
if ($type == self::BINARY) {
$number = $this->_math->fromBinary($number);
}
if (!preg_match("/^\d+$/", $number)) {
require_once('Zend/Crypt/DiffieHellman/Exception.php');
throw new Zend_Crypt_DiffieHellman_Exception('invalid parameter; not a positive natural number');
}
$this->_privateKey = (string) $number;
return $this;
}
/**
* Getter for the value of the private number
*
* @param string $type
* @return string
*/
public function getPrivateKey($type = self::NUMBER)
{
if (!$this->hasPrivateKey()) {
$this->setPrivateKey($this->_generatePrivateKey(), self::BINARY);
}
if ($type == self::BINARY) {
return $this->_math->toBinary($this->_privateKey);
} elseif ($type == self::BTWOC) {
return $this->_math->btwoc($this->_math->toBinary($this->_privateKey));
}
return $this->_privateKey;
}
/**
* Check whether a private key currently exists.
*
* @return boolean
*/
public function hasPrivateKey()
{
return isset($this->_privateKey);
}
/**
* Setter to pass an extension parameter which is used to create
* a specific BigInteger instance for a specific extension type.
* Allows manual setting of the class in case of an extension
* problem or bug.
*
* @param string $extension
* @return void
*/
public function setBigIntegerMath($extension = null)
{
/**
* @see Zend_Crypt_Math
*/
require_once 'Zend/Crypt/Math.php';
$this->_math = new Zend_Crypt_Math($extension);
}
/**
* In the event a private number/key has not been set by the user,
* or generated by ext/openssl, a best attempt will be made to
* generate a random key. Having a random number generator installed
* on linux/bsd is highly recommended! The alternative is not recommended
* for production unless without any other option.
*
* @return string
*/
protected function _generatePrivateKey()
{
$rand = $this->_math->rand($this->getGenerator(), $this->getPrime());
return $rand;
}
}
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @subpackage DiffieHellman
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Crypt_Exception
*/
require_once 'Zend/Crypt/Exception.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_DiffieHellman_Exception extends Zend_Crypt_Exception
{
}
\ No newline at end of file
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Exception.php 24593 2012-01-05 20:35:02Z matthew $
*/
/**
* @see Zend_Exception
*/
require_once 'Zend/Exception.php';
/**
* @category Zend
* @package Zend_Crypt
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Crypt_Exception extends Zend_Exception
{
}
\ No newline at end of file