Exemple #1
0
 function payload()
 {
     $root = new CXMLCreator("soap:Envelope");
     $root->setAttribute("xmlns:soap", BX_SOAP_ENV);
     // add the body
     $body = new CXMLCreator("soap:Body");
     // Check if it's a fault
     if (is_object($this->Value) && ToUpper(get_class($this->Value)) == 'CSOAPFAULT') {
         $fault = new CXMLCreator("soap:Fault");
         $faultCodeNode = new CXMLCreator("faultcode");
         $faultCodeNode->setData($this->Value->faultCode());
         $fault->addChild($faultCodeNode);
         $faultStringNode = new CXMLCreator("faultstring");
         $faultStringNode->setData($this->Value->faultString());
         $fault->addChild($faultStringNode);
         if ($this->Value->detail) {
             $fault->addChild($this->Value->detail());
         }
         $body->addChild($fault);
     } else {
         // add the request
         $responseName = $this->Name . "Response";
         $response = new CXMLCreator($responseName);
         $response->setAttribute("xmlns", $this->Namespace);
         if (!isset($this->typensVars[$this->Name]["output"]) or !count($this->typensVars[$this->Name]["output"])) {
             if (count($this->typensVars)) {
                 $GLOBALS['APPLICATION']->ThrowException("payload() can't find output type declaration.", "SoapRespnose::payload()");
                 return;
             } else {
                 //print_r($this->Value);
                 //die();
                 // EncodeLight
                 $value = CXMLCreator::encodeValueLight($this->ValueName, $this->Value);
             }
             $response->addChild($value);
         } else {
             //$return = new CXMLCreator($returnType);
             $valueEncoder = new CSOAPCodec();
             $valueEncoder->setTypensVars($this->typensVars);
             foreach ($this->typensVars[$this->Name]["output"] as $returnType => $returnParam) {
                 if (!$returnType) {
                     $GLOBALS['APPLICATION']->ThrowException("payload() can't find output type declaration for {$this->Name}.", "SoapRespnose::payload()");
                     return;
                 }
                 $valueEncoder->setOutputVars($this->Name);
                 $value = $valueEncoder->encodeValue($returnType, isset($this->Value[$returnType]) ? $this->Value[$returnType] : $this->Value);
                 $response->addChild($value);
             }
             //AddM
         }
         $body->addChild($response);
     }
     $root->addChild($body);
     //AddMessage2Log($root->getXML());
     return CXMLCreator::getXMLHeader() . $root->getXML();
 }
Exemple #2
0
 public static function __createFromDOM($domNode)
 {
     $result = new CXMLCreator($domNode->name);
     $result->setData($domNode->content);
     if (is_array($domNode->attributes)) {
         foreach ($domNode->attributes as $attrDomNode) {
             $result->setAttribute($attrDomNode->name, $attrDomNode->content);
         }
     }
     if (is_array($domNode->children)) {
         foreach ($domNode->children as $domChild) {
             $result->addChild(CXMLCreator::__createFromDOM($domChild));
         }
     }
     return $result;
 }
Exemple #3
0
	public function UpdateListItems($listName, $updates)
	{
		global $USER;

		$arStatusValues = array_flip($this->arStatusValues);
		$arPriorityValues = array_flip($this->arPriorityValues);

		if (!$listName_original = CIntranetUtils::checkGUID($listName))
			return new CSoapFault('Data error', 'Wrong GUID - '.$listName);

		$obResponse = new CXMLCreator('Results');

		$listName = ToUpper(CIntranetUtils::makeGUID($listName_original));
		$arSections = CCalendarSect::GetList(array('arFilter' => array('XML_ID' => $listName_original)));
		if (!$arSections || !is_array($arSections[0]))
			return new CSoapFault(
				'List not found',
				'List with '.$listName.' GUID not found'
			);
		$arSection = $arSections[0];

		$bGroup = $arSection['CAL_TYPE'] == 'group';
		$calType = $arSection['CAL_TYPE'];
		$ownerId = $arSection['OWNER_ID'];

		if ($bGroup)
		{
			CModule::IncludeModule('socialnetwork');
			$arGroupTmp = CSocNetGroup::GetByID($arSection['SOCNET_GROUP_ID']);
			if ($arGroupTmp["CLOSED"] == "Y")
				if (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") != "Y")
					return new CSoapFault('Cannot modify archive group calendar', 'Cannot modify archive group calendar');
		}

		$obBatch = $updates->children[0];
		$atrONERROR = $obBatch->getAttribute('OnError');
		$atrDATEINUTC = $obBatch->getAttribute('DateInUtc');
		$atrPROPERTIES = $obBatch->getAttribute('Properties');

		$arChanges = $obBatch->children;

		$arResultIDs = array();
		$dateStart = ConvertTimeStamp(strtotime('-1 hour'), 'FULL');
		$arResponseRows = array();
		$arReplicationIDs = array();
		$userId = (is_object($USER) && $USER->GetID()) ? $USER->GetID() : 1;

		foreach ($arChanges as $obMethod)
		{
			$arData = array('_command' => $obMethod->getAttribute('Cmd'));

			foreach ($obMethod->children as $obField)
			{
				$name = $obField->getAttribute('Name');
				if ($name == 'MetaInfo')
					$name .= '_'.$obField->getAttribute('Property');

				$arData[$name] = $obField->content;
			}

			if ($arData['_command'] == 'Delete')
			{
				$obRes = new CXMLCreator('Result');
				$obRes->setAttribute('ID', $obMethod->getAttribute('ID').','.$arData['_command']);
				$obRes->setAttribute('List', $listName);
				$obRes->addChild($obNode = new CXMLCreator('ErrorCode'));

				$res = CCalendar::DeleteEvent($arData['ID']);
				if ($res === true)
					$obNode->setData('0x00000000');
				else
					$obNode->setData('0x81020014');

				/*
					0x00000000 - ok
					0x81020015 - data conflict
					0x81020014 - generic error such as invalid value for Field
					0x81020016 - item does not exist
				*/

				$obResponse->addChild($obRes);
			}
			elseif ($arData['_command'] == 'New' || $arData['_command'] == 'Update')
			{
				$q = ToLower($arData['Description']);
				if (($pos = strrpos($q, '</body>')) !== false) $arData['Description'] = substr($arData['Description'], 0, $pos);
				if (($pos = strpos($q, '<body>')) !== false) $arData['Description'] = substr($arData['Description'], $pos + 6);

				$arData['Description'] = str_replace('</DIV>', "\r\n</DIV>", $arData['Description']);
				$arData['Description'] = str_replace(array("&#10;", "&#13;"), "", $arData['Description']);
				$arData['Description'] = preg_replace("/<![^>]*>/", '', $arData['Description']);
				//$arData['Description'] = strip_tags($arData['Description']);
				$arData['Description'] = trim($arData['Description']);

				$arData['Location'] = trim($arData['Location']);

				if (isset($arData['EventDate']))
				{
					$arData['EventDate'] = $this->__makeTS($arData['EventDate']);
					$arData['EndDate'] = $this->__makeTS($arData['EndDate']) + ($arData['fAllDayEvent'] ? -86340 : 0);
					$TZBias = intval(date('Z', $arData['EventDate']));
				}

				$arData['EventType'] = intval($arData['EventType']);

				if ($arData['EventType'] == 2)
					$arData['EventType'] = 0;

				if ($arData['EventType'] > 2 /* || ($arData['EventType'] == 1 && !$arData['RecurrenceData'])*/)
					return new CSoapFault(
						'Unsupported event type',
						'Event type unsupported'
					);

				$arData['fRecurrence'] = intval($arData['fRecurrence']);
				$arData['RRULE'] = '';

				$id = $arData['_command'] == 'New' ? 0 : intVal($arData['ID']);
				if ($arData['RecurrenceData'])
				{
					//$xmlstr = $arData['XMLTZone'];
					//$arData['XMLTZone'] = new CDataXML();
					//$arData['XMLTZone']->LoadString($xmlstr);

					$xmlstr = $arData['RecurrenceData'];
					$obRecurData = new CDataXML();
					$obRecurData->LoadString($xmlstr);

/*
<recurrence>
		<rule>
			<firstDayOfWeek>mo</firstDayOfWeek>
			<repeat>
				<weekly mo='TRUE' tu='TRUE' th='TRUE' sa='TRUE' weekFrequency='1' />
			</repeat>
			<repeatForever>FALSE</repeatForever>
		</rule>
</recurrence>
<deleteExceptions>true</deleteExceptions>
*/

					$obRecurRule = $obRecurData->tree->children[0]->children[0];
					$obRecurRepeat = $obRecurRule->children[1];
					$obNode = $obRecurRepeat->children[0];

					$arData['RRULE'] = array();
					switch($obNode->name)
					{
						case 'daily':
							// hack. we have no "work days" daily recurence
							if ($obNode->getAttribute('weekday') == 'TRUE')
							{
								$arData['RRULE']['FREQ'] = 'WEEKLY';
								$arData['RRULE']['BYDAY'] = 'MO,TU,WE,TH,FR';
								$arData['RRULE']['INTERVAL'] = 1;
							}
							else
							{
								$arData['RRULE']['FREQ'] = 'DAILY';
								$arData['RRULE']['INTERVAL'] = $obNode->getAttribute('dayFrequency');
							}

							$time_end = strtotime(
								date(date('Y-m-d', $arData['EventDate']).' H:i:s', $arData['EndDate'])
							);

							$arData['DT_LENGTH'] = $time_end - $arData['EventDate'];
						break;

						case 'weekly':
							$arData['RRULE']['FREQ'] = 'WEEKLY';
							$arData['RRULE']['BYDAY'] = '';

							$arWeekDays = array('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su');
							foreach ($arWeekDays as $day => $value)
							{
								if ($obNode->getAttribute($value))
									$arData['RRULE']['BYDAY'][] = strtoupper($value);
							}

							$arData['RRULE']['BYDAY'] = implode(',', $arData['RRULE']['BYDAY']);
							$arData['RRULE']['INTERVAL'] = $obNode->getAttribute('weekFrequency');

							$time_end = strtotime(date(date('Y-m-d', $arData['EventDate']).' H:i:s', $arData['EndDate']));

							$arData['DT_LENGTH'] = $time_end - $arData['EventDate'];
						break;

						case 'monthly':
							$arData['RRULE']['FREQ'] = 'MONTHLY';
							$arData['RRULE']['INTERVAL'] = $obNode->getAttribute('monthFrequency');
							$time_end = strtotime(date(date('Y-m', $arData['EventDate']).'-d H:i:s', $arData['EndDate']));

							$arData['DT_LENGTH'] = $time_end - $arData['EventDate'];
						break;

						case 'yearly':
							$arData['RRULE']['FREQ'] = 'YEARLY';
							$arData['RRULE']['INTERVAL'] = $obNode->getAttribute('yearFrequency');

							$time_end = strtotime(date(date('Y', $arData['EventDate']).'-m-d H:i:s', $arData['EndDate']));

							$arData['DT_LENGTH'] = $time_end - $arData['EventDate'];
						break;
					}

					if ($arData['DT_LENGTH'] == 0 && isset($arData['RRULE']['FREQ']))
						$arData['DT_LENGTH'] = 86400;

					$obWhile = $obRecurRule->children[2];
					if ($obWhile->name == 'repeatForever')
					{
						$arData['EndDate'] = MakeTimeStamp('');
					}
					elseif ($obWhile->name == 'windowEnd')
					{
						$arData['EndDate'] = $this->__makeTS($obWhile->textContent());
						$arData['RRULE']['UNTIL'] = ConvertTimeStamp($arData['EndDate'], 'FULL');
					}
				}
				elseif($arData['fRecurrence'] == -1 && $id > 0)
				{
					$arData['RRULE'] = -1;
				}

				if (isset($arData['EventDate']))
				{
					$skipTime = $arData['fAllDayEvent'] ? 'Y' : 'N';
					$TZBias = $arData['fAllDayEvent'] ? 0 : $TZBias;
					$arData['EventDate'] += $TZBias;
					$arData['EndDate'] += $TZBias;

//					$arData["DT_FROM"] = ConvertTimeStamp($arData['EventDate'], 'FULL');
//					$arData["DT_TO"] = ConvertTimeStamp($arData['EndDate'], 'FULL');
				}
				else
				{
					$arData["DT_FROM"] = -1;
					$arData["DT_TO"] = -1;
				}

				// fields
				$arFields = array(
					"ID" => $id,
					'CAL_TYPE' => $calType,
					'OWNER_ID' => $ownerId,
					'CREATED_BY' => $userId,
					'DT_FROM_TS' => $arData['EventDate'],
					'DT_TO_TS' => $arData['EndDate'],
					'DT_SKIP_TIME' => $skipTime,
//					"DT_FROM" => $arData["DT_FROM"],
//					"DT_TO" => $arData["DT_TO"],
					'NAME' => $arData['Title'],
					'DESCRIPTION' => CCalendar::ParseHTMLToBB($arData['Description']),
					'SECTIONS' => array($arSection['ID']),
					'ACCESSIBILITY' => $arStatusValues[$arData['MetaInfo_BusyStatus']],
					'IMPORTANCE' => $arPriorityValues[$arData['MetaInfo_Priority']],
					'RRULE' => $arData['RRULE'],
					'LOCATION' => CCalendar::UnParseTextLocation($arData['Location'])
				);

				if (isset($arData['DT_LENGTH']) && $arData['DT_LENGTH'] > 0)
					$arFields['DT_LENGTH'] = $arData['DT_LENGTH'];

				$EventID = CCalendar::SaveEvent(
					array(
						'arFields' => $arFields,
						'fromWebservice' => true
					)
				);

				if ($EventID)
				{
					// dirty hack
					$arReplicationIDs[$EventID] = $arData['MetaInfo_ReplicationID'];

					$arResponseRows[$EventID] = new CXMLCreator('Result');
					$arResponseRows[$EventID]->setAttribute('ID', $obMethod->getAttribute('ID').','.$arData['_command']);
					$arResponseRows[$EventID]->setAttribute('List', $listName);

					$arResponseRows[$EventID]->addChild($obNode = new CXMLCreator('ErrorCode'));
					$obNode->setData('0x00000000');
					//$arResponseRows[$EventID]->setAttribute('Version', 3);
				}
			}
		}

		$userId = (is_object($USER) && $USER->GetID()) ? $USER->GetID() : 1;
		$fetchMeetings = CCalendar::GetMeetingSection($userId) == $arSection['ID'];
		$arEvents = CCalendarEvent::GetList(
			array(
				'arFilter' => array(
					'CAL_TYPE' => $calType,
					'OWNER_ID' => $ownerId,
					'SECTION' => $arSection['ID'],
					//'INCLUDE_INVITINGS' => 'N'
				),
				'getUserfields' => false,
				'parseRecursion' => false,
				'fetchAttendees' => false,
				'fetchMeetings' => $fetchMeetings,
				'userId' => $userId
			)
		);

		foreach ($arEvents as $key => $event)
		{
			if ($arResponseRows[$event['ID']])
			{
				$obRow = $this->__getRow($event, $listName, $last_change = 0);
				$obRow->setAttribute('xmlns:z', "#RowsetSchema");
				if ($arReplicationIDs[$event['ID']])
					$obRow->setAttribute('MetaInfo_ReplicationID', $arReplicationIDs[$event['ID']]);

				$arResponseRows[$event['ID']]->addChild($obRow);
			}
			$obResponse->addChild($arResponseRows[$event['ID']]);
		}
		return array('UpdateListItemsResult' => $obResponse);
	}
Exemple #4
0
 protected static function GetCurrencyList()
 {
     $ar = CCrmCurrencyHelper::PrepareListItems();
     $CXMLCreatorR = new CXMLCreator('CHOISES');
     foreach ($ar as $key => $value) {
         $CXMLCreator = new CXMLCreator('CHOISE', true);
         $CXMLCreator->setAttribute('id', $key);
         $CXMLCreator->setData($value);
         $CXMLCreatorR->addChild($CXMLCreator);
     }
     return $CXMLCreatorR;
 }
Exemple #5
0
 function GetAttachmentCollection($listName, $listItemID)
 {
     $start = microtime(true);
     if (!($listName_original = CIntranetUtils::checkGUID($listName))) {
         return new CSoapFault('Data error', 'Wrong GUID - ' . $listName);
     }
     $listName = ToUpper(CIntranetUtils::makeGUID($listName_original));
     $listItemID = intval($listItemID);
     $dbRes = CUser::GetByID($listItemID);
     //$dbRes = CUser::GetList(($by="id"), ($order="asc"), array("ID_EQUAL_EXACT"=>IntVal($listItemID)));
     //$dbRes = $GLOBALS['DB']->Query('SELECT PERSONAL_PHOTO FROM b_user WHERE id=\''.$listItemID.'\'');
     $obData = new CXMLCreator('Attachments');
     if (($arUser = $dbRes->Fetch()) && $arUser['PERSONAL_PHOTO']) {
         $arImage = self::InitImage($arUser['PERSONAL_PHOTO'], 100, 100);
         $obData->addChild($obAttachment = new CXMLCreator('Attachment'));
         $obAttachment->setData(CHTTP::URN2URI($arImage['CACHE']['src']));
         //$data = '<Attachments><Attachment>http://'.$_SERVER['SERVER_NAME'].$arImage['CACHE']['src'].'</Attachment></Attachments>';
     }
     // else
     // {
     // $data = '<Attachments></Attachments>';
     // }
     //return array('GetAttachmentCollectionResult' => $data);
     return array('GetAttachmentCollectionResult' => $obData);
 }
Exemple #6
0
 protected static function GetSourceList()
 {
     $ar = CCrmStatus::GetStatusListEx('SOURCE');
     $CXMLCreatorR = new CXMLCreator('CHOISES');
     foreach ($ar as $key => $value) {
         $CXMLCreator = new CXMLCreator('CHOISE', true);
         $CXMLCreator->setAttribute('id', $key);
         $CXMLCreator->setData($value);
         $CXMLCreatorR->addChild($CXMLCreator);
     }
     return $CXMLCreatorR;
 }
Exemple #7
0
 function encodeValue($name, $value, $complexDataTypeName = "")
 {
     global $xsd_simple_type;
     if (!is_array($this->outputVars) or !count($this->outputVars)) {
         CSOAPServer::ShowSOAPFault("encodeValue() has no Output Data Type Declaration for validation.");
         exit;
     }
     $dataType = "";
     $typeDeclaration = "";
     if (isset($this->outputVars[$name])) {
         $typeDeclaration = $this->outputVars[$name];
     } else {
         if (isset($this->typensVars[$name])) {
             $typeDeclaration = $this->typensVars[$name];
         } else {
             if (isset($this->typensVars[$complexDataTypeName][$name])) {
                 $typeDeclaration = $this->typensVars[$complexDataTypeName][$name];
             }
         }
     }
     if (isset($typeDeclaration["varType"])) {
         // if not, name = complex data type
         $dataType = $typeDeclaration["varType"];
     } else {
         $dataType = $name;
     }
     if (isset($xsd_simple_type[$dataType])) {
         $dataType = $xsd_simple_type[$dataType];
     }
     // Type validation
     $this->_validateType($dataType, $value);
     switch ($dataType) {
         case "string":
             $node = new CXMLCreator($name);
             //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":string" );
             $node->setData($value);
             return $node;
             break;
         case "boolean":
             $node = new CXMLCreator($name);
             //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":boolean" );
             if ($value === true) {
                 $node->setData("true");
             } else {
                 $node->setData("false");
             }
             return $node;
             break;
         case "integer":
             $node = new CXMLCreator($name);
             //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":int" );
             $node->setData(intval($value));
             return $node;
             break;
         case "float":
         case "double":
             $node = new CXMLCreator($name);
             //$node->setAttribute( "type", BX_SOAP_XSD_PREFIX . ":float" );
             $node->setData($value);
             return $node;
             break;
             // added by Sigurd
         // added by Sigurd
         case "base64":
         case "base64Binary":
             $node = new CXMLCreator($name);
             //$node->setAttribute("type", BX_SOAP_XSD_PREFIX . ":base64Binary" );
             $node->setData(base64_encode($value));
             return $node;
             break;
         case 'any':
             $node = new CXMLCreator($name);
             if (is_object($value)) {
                 // $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/ws.log', 'a');
                 // fwrite($fp, $value->GetTree()."\n");
                 // fwrite($fp, '===================================='."\r\n");
                 // fclose($fp);
                 if (get_class($value) == 'CDataXML') {
                     $node->addChild(CXMLCreator::CreateFromDOM($value->GetTree()));
                 } elseif (get_class($value) == 'CDataXMLDocument') {
                     $node->addChild(CXMLCreator::CreateFromDOM($value));
                 } elseif (get_class($value) == 'CXMLCreator') {
                     $node->addChild($value);
                 }
             } else {
                 $data = new CDataXML();
                 if ($data->LoadString($value)) {
                     $node->addChild(CXMLCreator::CreateFromDOM($data->GetTree()));
                 } else {
                     $node->setData($value);
                 }
             }
             return $node;
             break;
         default:
             $node = new CXMLCreator($name);
             if (isset($typeDeclaration["arrType"])) {
                 if (!isset($typeDeclaration["varType"])) {
                     $this->_errorTypeValidation("varType [undef]", $value);
                 }
                 $varType = $typeDeclaration["varType"];
                 // Decode array
                 $maxOccurs = 0;
                 $arrayType = $typeDeclaration["arrType"];
                 if (isset($typeDeclaration["maxOccursA"])) {
                     $maxOccurs = $typeDeclaration["maxOccursA"];
                 }
                 if (isset($xsd_simple_type[$arrayType])) {
                     $i = 0;
                     $arrayType = $xsd_simple_type[$arrayType];
                     $arrayTypeEl = $varType . "El";
                     // TODO: non fixed. get El name from wsdl. or decl.
                     if (!is_array($value)) {
                         CSOAPCodec::_errorTypeValidation("Array", $value);
                     }
                     foreach ($value as $valnode) {
                         $i++;
                         $this->_validateType($arrayType, $valnode);
                         $cndata = new CXMLCreator($arrayTypeEl);
                         $cndata->setData($valnode);
                         $node->addChild($cndata);
                         if (intval($maxOccurs) > 0 and $i > $maxOccurs) {
                             break;
                         }
                     }
                 } else {
                     // Complex data type arrays // $arrayType as is.
                     // TODO: non fixed. get $arrayTypeEl name from wsdl. or decl.
                     $i = 0;
                     $arrayTypeEl = $varType . "El";
                     if (!is_array($value)) {
                         CSOAPCodec::_errorTypeValidation("Array", $value);
                     }
                     foreach ($value as $valnode) {
                         $decoded = null;
                         $i++;
                         $this->_validateType($arrayType, $valnode);
                         $decoded = $this->encodeValue($arrayType, $valnode);
                         $cndata = new CXMLCreator($arrayTypeEl);
                         if ($decoded) {
                             $this->_validateClassType("CXMLCreator", $decoded);
                             $decoded->setName($arrayTypeEl);
                             $node->addChild($decoded);
                         }
                         if (intval($maxOccurs) > 0 and $i > $maxOccurs) {
                             break;
                         }
                     }
                 }
             } else {
                 // Here we goes with struct, or with class
                 // First, try to find declaration
                 $objectDecl = 0;
                 $returnValue = array();
                 $params = array();
                 if (!isset($this->typensVars[$dataType])) {
                     break;
                 }
                 $objectDecl = $this->typensVars[$dataType];
                 if (!$objectDecl) {
                     CSOAPServer::ShowSOAPFault("encodeValue() cant find complex type declaration for {$dataType}.");
                     exit;
                 }
                 // Type of serialization: class/assoc array
                 $objectClass = null;
                 $serialize = "assoc";
                 if (isset($objectDecl["serialize"])) {
                     $serialize = $objectDecl["serialize"];
                     unset($objectDecl["serialize"]);
                 }
                 // Validate hard complex data types
                 if ($serialize == "assoc") {
                     $this->_validateType("array", $value);
                 }
                 if ($serialize != "assoc") {
                     $this->_validateClassType($dataType, $value);
                 }
                 foreach ($objectDecl as $pname => $param) {
                     $decoded = null;
                     $strict = true;
                     if (isset($param["strict"])) {
                         $strict = $param["strict"] == "strict" ? true : false;
                     }
                     if ($serialize == "assoc") {
                         //var_dump($pname); var_dump($value[$pname]); die();
                         if (isset($value[$pname])) {
                             $decoded = $this->encodeValue($pname, $value[$pname], $dataType);
                         }
                     } else {
                         if ($serialize != "assoc") {
                             if (isset($value->{$pname})) {
                                 $decoded = $this->encodeValue($pname, $value->{$pname}, $dataType);
                             }
                         }
                     }
                     if ($decoded) {
                         $this->_validateClassType("CXMLCreator", $decoded);
                     }
                     if (!$decoded and !$strict) {
                         CSOAPServer::ShowSOAPFault("Request has no enought params of strict type to be decoded. ");
                         exit;
                     }
                     $node->addChild($decoded);
                 }
             }
             return $node;
             break;
     }
     return false;
 }
Exemple #8
0
 function __createPortType($portTypes)
 {
     if (is_array($portTypes)) {
         foreach ($portTypes as $class => $methods) {
             $pt = new CXMLCreator("wsdl:portType");
             $pt->setAttribute("name", $class . "Interface");
             foreach ($methods as $method => $components) {
                 $op = new CXMLCreator("wsdl:operation");
                 $op->setAttribute("name", $method);
                 $input = new CXMLCreator("wsdl:input");
                 $input->setAttribute("message", "tns:" . $method . "SoapIn");
                 $op->addChild($input);
                 $output = new CXMLCreator("wsdl:output");
                 $output->setAttribute("message", "tns:" . $method . "SoapOut");
                 $op->addChild($output);
                 if ($components["documentation"]) {
                     $doc = new CXMLCreator("wsdl:documentation");
                     $doc->setData($components["documentation"]);
                     $op->addChild($doc);
                 }
                 $pt->addChild($op);
             }
             $this->portTypes[] = $pt;
         }
     }
 }
 function UpdateListItems($listName, $updates)
 {
     global $USER, $DB;
     $arPaths = array('user' => COption::GetOptionString('intranet', 'path_task_user_entry', '/company/personal/user/#USER_ID#/tasks/task/view/#TASK_ID#/'), 'group' => COption::GetOptionString('intranet', 'path_task_group_entry', '/workgroups/group/#GROUP_ID#/tasks/task/view/#TASK_ID#/'));
     if (!$this->__Init()) {
         return $this->error;
     }
     if (!($listName_original = CIntranetUtils::checkGUID($listName))) {
         return new CSoapFault('Data error', 'Wrong GUID - ' . $listName);
     }
     $listName = ToUpper(CIntranetUtils::makeGUID($listName_original));
     $obResponse = new CXMLCreator('Results');
     $obBatch = $updates->children[0];
     $atrONERROR = $obBatch->getAttribute('OnError');
     $atrDATEINUTC = $obBatch->getAttribute('DateInUtc');
     $atrPROPERTIES = $obBatch->getAttribute('Properties');
     $arChanges = $obBatch->children;
     $arResultIDs = array();
     $dateStart = ConvertTimeStamp(strtotime('-1 hour'), 'FULL');
     $arResponseRows = array();
     $arResponseRowsError = array();
     $arReplicationIDs = array();
     foreach ($arChanges as $obMethod) {
         $arData = array('_command' => $obMethod->getAttribute('Cmd'));
         $ID = false;
         $bUpdate = true;
         $arElement = false;
         $arSection = $this->arUsersSection;
         foreach ($obMethod->children as $obField) {
             $name = $obField->getAttribute('Name');
             if ($name == 'MetaInfo') {
                 $name .= '_' . $obField->getAttribute('Property');
             }
             $arData[$name] = $obField->content;
         }
         $obResponseRow = new CXMLCreator('Result');
         $obResponseRow->setAttribute('ID', $obMethod->getAttribute('ID') . ',' . $arData['_command']);
         $obResponseRow->setAttribute('List', $listName);
         $obResponseRow->addChild($obErrorCode = new CXMLCreator('ErrorCode'));
         if ($arData['ID'] > 0) {
             $rsElement = CTasks::GetById($arData['ID']);
             if ($rsElement && ($arElement = $rsElement->Fetch())) {
                 if (!is_array($arElement)) {
                     $obErrorCode->setData('0x81020016');
                     $bUpdate = false;
                 } else {
                     if ($arElement['taskType'] == "group") {
                         $arGroupTmp = CSocNetGroup::GetByID($arElement['ownerId']);
                         if ($arGroupTmp["CLOSED"] == "Y") {
                             if (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") != "Y") {
                                 return new CSoapFault('Cannot modify archive group task', 'Cannot modify archive group task');
                             }
                         }
                     }
                     $arElement['arParams'] = array(intval($arElement['GROUP_ID']) > 0 ? 'PATH_TO_USER_TASKS_TASK' : 'PATH_TO_GROUP_TASKS_TASK' => str_replace(array('#USER_ID#', '#GROUP_ID#', '#TASK_ID#'), array($USER->GetID(), $arSection['XML_ID'], $arElement['ID']), $arPaths[$arElement['taskType']]));
                 }
             } else {
                 $obErrorCode->setData('0x81020016');
                 $bUpdate = false;
             }
         }
         if ($bUpdate) {
             if ($arData['_command'] == 'Delete' && $arElement["CREATED_BY"] == $USER->GetID()) {
                 $arError = false;
                 if (!CTasks::Delete($arElement['ID'])) {
                     $obErrorCode->setData('0x81020014');
                 } else {
                     $obErrorCode->setData('0x00000000');
                 }
             } elseif ($arData['_command'] == 'New' || $arData['_command'] == 'Update') {
                 $arData['Body'] = trim($arData['Body']);
                 $arData['Body'] = str_replace(array("&#10;", "&#13;", '&nbsp;'), "", $arData['Body']);
                 $arData['Body'] = preg_replace("/<![^>]*>/", '', $arData['Body']);
                 if (($pos = strpos($arData['Body'], '<BODY>')) !== false) {
                     $arData['Body'] = substr($arData['Body'], $pos + 6);
                 }
                 echo $pos . ' ';
                 if (($pos = strpos($arData['Body'], '</BODY>')) !== false) {
                     $arData['Body'] = substr($arData['Body'], 0, $pos);
                 }
                 echo $pos . ' ';
                 $TZBias = intval(date('Z'));
                 $arData['StartDate'] = $arData['StartDate'] ? $this->__makeTS($arData['StartDate']) + $TZBias : '';
                 $arData['DueDate'] = $arData['DueDate'] ? $this->__makeTS($arData['DueDate']) + $TZBias : '';
                 $arData['MetaInfo_DateComplete'] = $arData['MetaInfo_DateComplete'] ? $this->__makeTS($arData['EndDate']) + $TZBias : '';
                 $probablyHtmlInDescription = strpos($arData['Body'], '<') !== false && strpos($arData['Body'], '>');
                 $arFields = array('DESCRIPTION_IN_BBCODE' => $probablyHtmlInDescription ? 'N' : 'Y', 'CHANGED_BY' => $USER->GetID(), 'CHANGED_DATE' => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time()), 'SITE_ID' => SITE_ID, 'TITLE' => $arData['Title'], 'START_DATE_PLAN' => $arData['StartDate'] ? ConvertTimeStamp($arData['StartDate']) : '', 'DEADLINE' => $arData['DueDate'] ? ConvertTimeStamp($arData['DueDate']) : '', 'DESCRIPTION' => $arData['Body'], 'PRIORITY' => isset($arData['Priority']) ? intval($arData['Priority']) : 1, 'DURATION_PLAN' => $arData['MetaInfo_TotalWork'] / 60, 'DURATION_FACT' => $arData['MetaInfo_ActualWork'] / 60, 'CLOSED_DATE' => $arData['MetaInfo_DateComplete'] ? ConvertTimeStamp($arData['MetaInfo_DateComplete']) : '');
                 if (in_array($arData['Status'], $this->arStatuses)) {
                     $arFields["STATUS"] = $arData['Status'];
                 }
                 if ($assigned_to = $arData['AssignedTo']) {
                     if ($USER_ID = $this->__getUser($assigned_to)) {
                         $arFields['RESPONSIBLE_ID'] = $USER_ID;
                     } else {
                         $obErrorCode->setData('0x81020054');
                         $bUpdate = false;
                     }
                 } else {
                     $arFields['RESPONSIBLE_ID'] = $USER->getId();
                 }
                 if ($bUpdate) {
                     CTimeZone::Disable();
                     $ID = 0;
                     $obTask = new CTasks();
                     $arError = false;
                     if ($arData['_command'] == 'New') {
                         if ($arFields["RESPONSIBLE_ID"] == $USER->GetID() || CTasks::IsSubordinate($arFields["RESPONSIBLE_ID"], $USER->GetID())) {
                             $arFields["STATUS"] = 2;
                         } else {
                             $arFields["STATUS"] = 1;
                         }
                         $arFields['OUTLOOK_VERSION'] = 1;
                         $arFields["CREATED_BY"] = $USER->GetID();
                         $arFields["CREATED_DATE"] = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")), time());
                         if ($ID = $obTask->Add($arFields)) {
                             $arReplicationIDs[$ID] = $arData['MetaInfo_ReplicationID'];
                             $obErrorCode->setData('0x00000000');
                         }
                     } else {
                         if ($arElement["CREATED_BY"] == $USER->GetID() || $arElement["RESPONSIBLE_ID"] == $USER->GetID()) {
                             if ($arElement["CREATED_BY"] != $USER->GetID()) {
                                 unset($arFields["TITLE"], $arFields["START_DATE_PLAN"], $arFields["DESCRIPTION"], $arFields["PRIORITY"], $arFields["DURATION_PLAN"], $arFields["CLOSED_DATE"]);
                                 if ($arElement["ALLOW_CHANGE_DEADLINE"] != "Y") {
                                     unset($arFields["DEADLINE"]);
                                 }
                                 if ($arElement["TASK_CONTROL"] != "Y" && $arFields["STATUS"] == 5) {
                                     $arFields["STATUS"] = 4;
                                 }
                             } elseif ($arElement["RESPONSIBLE_ID"] != $USER->GetID() && ($arFields["STATUS"] == 6 || $arFields["STATUS"] == 3)) {
                                 unset($arFields["STATUS"]);
                             }
                             $arFields['OUTLOOK_VERSION'] = $arData['owshiddenversion'];
                             if (sizeof($arFields) > 0) {
                                 if ($obTask->Update($arData['ID'], $arFields)) {
                                     $ID = $arData['ID'];
                                     $obErrorCode->setData('0x00000000');
                                 }
                             }
                         }
                     }
                     CTimeZone::Enable();
                     if (is_array($obTask->GetErrors()) && count($obTask->GetErrors()) > 0) {
                         $ID = 0;
                         $obErrorCode->setData('0x81020014');
                         $bUpdate = false;
                     } else {
                         $taskType = $arElement ? $arElement['taskType'] : 'user';
                         $ownerId = $arElement ? $arElement['ownerId'] : $USER->GetID();
                         $arParams = $arElement ? $arElement['arParams'] : array('PATH_TO_USER_TASKS_TASK' => str_replace(array('#USER_ID#', '#GROUP_ID#', '#TASK_ID#'), array($USER->GetID(), $arSection['XML_ID'], $ID), $arPaths['user']));
                     }
                 }
             }
         }
         if ($ID > 0) {
             $arResponseRows[$ID] = $obResponseRow;
         } else {
             $arResponseRowsError[] = $obResponseRow;
         }
     }
     if (sizeof($arResponseRows) > 0) {
         $dbRes = CTasks::GetList(array('ID' => 'ASC'), array('ID' => array_keys($arResponseRows), 'MEMBER' => $USER->GetID()));
         while ($arRes = $dbRes->Fetch()) {
             if ($arResponseRows[$arRes['ID']]) {
                 $rsFiles = CTaskFiles::GetList(array(), array("TASK_ID" => $arRes["ID"]));
                 $arRes["FILES"] = array();
                 while ($arFiles = $rsFiles->Fetch()) {
                     $arRes["FILES"][] = $arFiles["FILE_ID"];
                 }
                 $obRow = $this->__getRow($arRes, $listName, $last_change = 0);
                 if ($arReplicationIDs[$arRes['ID']]) {
                     $obRow->setAttribute('ows_MetaInfo_ReplicationID', $arReplicationIDs[$arRes['ID']]);
                 }
                 $obRow->setAttribute('xmlns:z', "#RowsetSchema");
                 $arResponseRows[$arRes['ID']]->addChild($obRow);
                 $obResponse->addChild($arResponseRows[$arRes['ID']]);
             }
         }
     }
     foreach ($arResponseRowsError as $obChange) {
         $obResponse->addChild($obChange);
     }
     return array('UpdateListItemsResult' => $obResponse);
 }
Exemple #10
0
 function UpdateListItems($listName, $updates)
 {
     global $USER;
     $arPaths = array('user' => COption::GetOptionString('intranet', 'path_task_user_entry', '/company/personal/user/#USER_ID#/tasks/task/view/#TASK_ID#/'), 'group' => COption::GetOptionString('intranet', 'path_task_group_entry', '/workgroups/group/#GROUP_ID#/tasks/task/view/#TASK_ID#/'));
     if (!$this->__Init()) {
         return $this->error;
     }
     if (!($listName_original = CIntranetUtils::checkGUID($listName))) {
         return new CSoapFault('Data error', 'Wrong GUID - ' . $listName);
     }
     $listName = ToUpper(CIntranetUtils::makeGUID($listName_original));
     // one more dirty hack. now for bx.
     //define('BX_INTASKS_FROM_COMPONENT', true);
     //CModule::IncludeModule('socialnetwork');
     //include($_SERVER['DOCUMENT_ROOT'].BX_PERSONAL_ROOT.'/components/bitrix/intranet.tasks/init.php');
     //include($_SERVER['DOCUMENT_ROOT'].BX_PERSONAL_ROOT.'/components/bitrix/intranet.tasks/action.php');
     $obResponse = new CXMLCreator('Results');
     $arStatusValues = array();
     $obStatus = CIBlockProperty::GetPropertyEnum('TaskStatus', array('SORT' => 'asc'), array('IBLOCK_ID' => $this->IBLOCK_ID));
     while ($arStatus = $obStatus->Fetch()) {
         $arStatusValues[$arStatus['XML_ID']] = $arStatus['ID'];
         if ($arStatus['XML_ID'] == 'NotAccepted') {
             $arStatusValues[$arStatus['VALUE']] = $arStatus['ID'];
         }
     }
     /*
     $arPriorityValues = array();
     $obPriority = CIBlockProperty::GetPropertyEnum('TaskPriority', array('SORT' => 'asc'), array('IBLOCK_ID' => $this->IBLOCK_ID));
     while ($arPriority = $obPriority->Fetch())
     	$arPriorityValues[$arPriority['XML_ID']] = $arPriority['ID'];
     */
     $arPriorityValues = array_flip($this->arProperties['TaskPriority']['VARIANTS_ID']);
     $arStatusValues = array_flip($this->arProperties['TaskStatus']['VARIANTS_ID']);
     $arStatusXML_ID = array_flip($this->arProperties['TaskStatus']['VARIANTS']);
     $obBatch = $updates->children[0];
     $atrONERROR = $obBatch->getAttribute('OnError');
     $atrDATEINUTC = $obBatch->getAttribute('DateInUtc');
     $atrPROPERTIES = $obBatch->getAttribute('Properties');
     $arChanges = $obBatch->children;
     $arResultIDs = array();
     $dateStart = ConvertTimeStamp(strtotime('-1 hour'), 'FULL');
     $arResponseRows = array();
     $arResponseRowsError = array();
     $arReplicationIDs = array();
     foreach ($arChanges as $obMethod) {
         $arData = array('_command' => $obMethod->getAttribute('Cmd'));
         $ID = false;
         $bUpdate = true;
         $arElement = false;
         $arSection = $this->arUsersSection;
         foreach ($obMethod->children as $obField) {
             $name = $obField->getAttribute('Name');
             if ($name == 'MetaInfo') {
                 $name .= '_' . $obField->getAttribute('Property');
             }
             $arData[$name] = $obField->content;
         }
         $obResponseRow = new CXMLCreator('Result');
         $obResponseRow->setAttribute('ID', $obMethod->getAttribute('ID') . ',' . $arData['_command']);
         $obResponseRow->setAttribute('List', $listName);
         $obResponseRow->addChild($obErrorCode = new CXMLCreator('ErrorCode'));
         if ($arData['ID'] > 0) {
             //$dbRes = CIBlockElement::GetByID($arData['ID']);
             $arElement = CIntranetTasks::GetById($arData['ID']);
             if (!is_array($arElement)) {
                 $obErrorCode->setData('0x81020016');
                 $bUpdate = false;
             } else {
                 //$arElement = $obElement->GetFields();
                 //$arElement['prop'] = $obElement->GetProperties();
                 if ($arElement['IBLOCK_SECTION_ID'] != $arSection['ID']) {
                     if (!($arSection = $this->__getSection($arElement['IBLOCK_SECTION_ID']))) {
                         return new CSoapFault('Some error', 'Unknown error with iblock sections');
                     }
                 }
                 // don't forget about depth of sections, Max has modification
                 if ($arElement['taskType'] == "group") {
                     $arGroupTmp = CSocNetGroup::GetByID($arElement['ownerId']);
                     if ($arGroupTmp["CLOSED"] == "Y") {
                         if (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") != "Y") {
                             return new CSoapFault('Cannot modify archive group task', 'Cannot modify archive group task');
                         }
                     }
                 }
                 $arElement['arParams'] = array($arElement['taskType'] == 'user' ? 'PATH_TO_USER_TASKS_TASK' : 'PATH_TO_GROUP_TASKS_TASK' => str_replace(array('#USER_ID#', '#GROUP_ID#', '#TASK_ID#'), array($USER->GetID(), $arSection['XML_ID'], $arElement['ID']), $arPaths[$arElement['taskType']]));
             }
         }
         if ($bUpdate) {
             if ($arData['_command'] == 'Delete') {
                 $arError = false;
                 if (CIntranetTasksDocument::CanUserOperateDocument(INTASK_DOCUMENT_OPERATION_DELETE_DOCUMENT, $USER->GetID(), $arElement['ID'], array())) {
                     if (!CIntranetTasks::Delete($arElement['ID'], $arError)) {
                         $obErrorCode->setData('0x81020014');
                     } else {
                         $obErrorCode->setData('0x00000000');
                     }
                 } else {
                     $obErrorCode->setData('0x81020014');
                 }
                 /*
                 	0x00000000 - ok
                 	0x81020015 - data conflict
                 	0x81020014 - generic error such as invalid value for Field
                 	0x81020016 - item does not exist
                 */
             } elseif ($arData['_command'] == 'New' || $arData['_command'] == 'Update') {
                 /*
                 $arData['Body'] = str_replace('</DIV>', "\r\n</DIV>", $arData['Body']);
                 $arData['Body'] = strip_tags($arData['Body']);
                 $arData['Body'] = trim($arData['Body']);
                 $arData['Body'] = htmlspecialcharsback($arData['Body']);
                 */
                 $arData['Body'] = trim($arData['Body']);
                 $arData['Body'] = str_replace(array("&#10;", "&#13;", '&nbsp;'), "", $arData['Body']);
                 $arData['Body'] = preg_replace("/<![^>]*>/", '', $arData['Body']);
                 if (($pos = strpos($arData['Body'], '<BODY>')) !== false) {
                     $arData['Body'] = substr($arData['Body'], $pos + 6);
                 }
                 echo $pos . ' ';
                 if (($pos = strpos($arData['Body'], '</BODY>')) !== false) {
                     $arData['Body'] = substr($arData['Body'], 0, $pos);
                 }
                 echo $pos . ' ';
                 $TZBias = intval(date('Z'));
                 $arData['StartDate'] = $arData['StartDate'] ? $this->__makeTS($arData['StartDate']) + $TZBias : '';
                 $arData['DueDate'] = $arData['DueDate'] ? $this->__makeTS($arData['DueDate']) + $TZBias : '';
                 $arData['MetaInfo_DateComplete'] = $arData['MetaInfo_DateComplete'] ? $this->__makeTS($arData['EndDate']) + $TZBias : '';
                 if ($arData['Status'] == $arStatusValues['NotAccepted']) {
                     $arData['Status'] = 'NotAccepted';
                 }
                 $arFields = array('IBLOCK_ID' => $this->IBLOCK_ID, 'IBLOCK_SECTION_ID' => $arSection['ID'], 'MODIFIED_BY' => $USER->GetID(), 'NAME' => $arData['Title'] ? $arData['Title'] : GetMessage('INTR_OUTLOOK_TASK_NO_TITLE'), 'DATE_ACTIVE_FROM' => $arData['StartDate'] ? ConvertTimeStamp($arData['StartDate']) : '', 'DATE_ACTIVE_TO' => $arData['DueDate'] ? ConvertTimeStamp($arData['DueDate']) : '', 'DETAIL_TEXT_TYPE' => 'html', 'DETAIL_TEXT' => $arData['Body'], 'PROPERTY_TaskPriority' => $arData['Priority'] ? $arPriorityValues[$arData['Priority']] : false, 'PROPERTY_TaskComplete' => $arData['PercentComplete'] * 100, 'PROPERTY_TaskSize' => $arData['MetaInfo_TotalWork'] / 60, 'PROPERTY_TaskSizeReal' => $arData['MetaInfo_ActualWork'] / 60, 'PROPERTY_TaskFinish' => $arData['MetaInfo_DateComplete'] ? ConvertTimeStamp($arData['MetaInfo_DateComplete']) : '');
                 if (false === $arFields['PROPERTY_TaskPriority']) {
                     $arPrior = array_keys($arElement['PROPERTY_TaskPriority']);
                     $arFields['PROPERTY_TaskPriority'] = $arPrior[0];
                 }
                 if ($assigned_to = $arData['AssignedTo']) {
                     if ($USER_ID = $this->__getUser($assigned_to)) {
                         $arFields['PROPERTY_TaskAssignedTo'] = $USER_ID;
                     } else {
                         $obErrorCode->setData('0x81020054');
                         $bUpdate = false;
                     }
                 }
                 if ($bUpdate) {
                     $bConfirm = false;
                     $bComplete = false;
                     if ($arData['_command'] != 'New') {
                         if (false && $arElement['PROPERTY_VERSION'] > $arData['owshiddenversion']) {
                             $obErrorCode->setData('0x81020015');
                             $bUpdate = false;
                         } else {
                             foreach ($arElement as $fld => $value) {
                                 if (substr($fld, 0, 9) == 'PROPERTY_') {
                                     if (!$arFields[$fld] && $fld != 'PROPERTY_TaskFiles') {
                                         $arFields[$fld] = $arElement[$fld];
                                     }
                                 }
                             }
                             $arFields['PROPERTY_VERSION']++;
                         }
                         $statusOld = $this->__GetTaskStatus($arElement['ID'], $arElement['IBLOCK_ID']);
                     } else {
                         $arFields['PROPERTY_VERSION'] = $arData['owshiddenversion'];
                         $statusOld = -1;
                     }
                     if (!$arFields['PROPERTY_TaskPriority']) {
                         $arFields['PROPERTY_TaskPriority'] = 2;
                     }
                     if (!$arFields['PROPERTY_TaskAssignedTo']) {
                         $arFields['PROPERTY_TaskAssignedTo'] = $USER->GetID();
                     } elseif ($arFields['PROPERTY_TaskAssignedTo'] != $USER->GetID()) {
                         $arData['Status'] = 'NotAccepted';
                     }
                     $statusNew = $arData['Status'] ? $arStatusXML_ID[$arData['Status']] : $statusOld;
                     $ID = 0;
                     if ($bUpdate) {
                         $arError = false;
                         if ($arData['_command'] == 'New') {
                             if ($ID = CIntranetTasks::Add($arFields, $arError)) {
                                 $arDocumentStates = CBPDocument::GetDocumentStates(array("intranet", "CIntranetTasksDocument", "x" . $this->IBLOCK_ID), null);
                                 $arDocumentStates = array_values($arDocumentStates);
                                 $pathTemplate = str_replace(array("#USER_ID#", "#TASK_ID#"), array($USER->GetID(), "{=Document:ID}"), COption::GetOptionString("intranet", "path_task_user_entry", "/company/personal/user/#USER_ID#/tasks/task/view/#TASK_ID#/"));
                                 $arErrors = array();
                                 CBPDocument::StartWorkflow($arDocumentStates[0]["TEMPLATE_ID"], array("intranet", "CIntranetTasksDocument", $ID), array("OwnerId" => $arFields['PROPERTY_TaskAssignedTo'], "TaskType" => 'user', "PathTemplate" => $pathTemplate, "ForumId" => COption::GetOptionInt('intranet', 'task_forum_id', 0), "IBlockId" => $this->IBLOCK_ID), $arErrors);
                                 CIntranetTasks::ChangeStatus($ID, $statusNew);
                                 $arReplicationIDs[$ID] = $arData['MetaInfo_ReplicationID'];
                                 $obErrorCode->setData('0x00000000');
                             }
                         } else {
                             if (CIntranetTasks::Update($arData['ID'], $arFields, $arError)) {
                                 if ($statusOld != $statusNew) {
                                     CIntranetTasks::ChangeStatus($arData['ID'], $statusNew);
                                 }
                                 $ID = $arData['ID'];
                                 $obErrorCode->setData('0x00000000');
                             }
                         }
                         if (is_array($arError) && count($arError) > 0) {
                             $ID = 0;
                             $obErrorCode->setData('0x81020014');
                             $bUpdate = false;
                         } else {
                             $taskType = $arElement ? $arElement['taskType'] : 'user';
                             $ownerId = $arElement ? $arElement['ownerId'] : $USER->GetID();
                             $arParams = $arElement ? $arElement['arParams'] : array('PATH_TO_USER_TASKS_TASK' => str_replace(array('#USER_ID#', '#GROUP_ID#', '#TASK_ID#'), array($USER->GetID(), $arSection['XML_ID'], $ID), $arPaths['user']));
                         }
                     }
                 }
             }
         }
         if ($ID > 0) {
             $arResponseRows[$ID] = $obResponseRow;
         } else {
             $arResponseRowsError[] = $obResponseRow;
         }
     }
     $dbRes = CIntranetTasks::GetList(array('ID' => 'ASC'), array('IBLOCK_ID' => $this->IBLOCK_ID, 'ID' => array_keys($arResponseRows)));
     while ($arRes = $dbRes->Fetch()) {
         if ($arResponseRows[$arRes['ID']]) {
             $obRow = $this->__getRow($arRes, $listName, $last_change = 0);
             if ($arReplicationIDs[$arRes['ID']]) {
                 $obRow->setAttribute('ows_MetaInfo_ReplicationID', $arReplicationIDs[$arRes['ID']]);
             }
             $obRow->setAttribute('xmlns:z', "#RowsetSchema");
             $arResponseRows[$arRes['ID']]->addChild($obRow);
             $obResponse->addChild($arResponseRows[$arRes['ID']]);
         }
     }
     foreach ($arResponseRowsError as $obChange) {
         $obResponse->addChild($obChange);
     }
     return array('UpdateListItemsResult' => $obResponse);
 }
Exemple #11
0
 public function AddWebserviceFields(&$obFields)
 {
     $arUserFields = $this->GetUserFields($this->sEntityID, 0, LANGUAGE_ID);
     foreach ($arUserFields as $FIELD_NAME => $arUserField) {
         $defVal = '';
         if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'employee') {
             continue;
         }
         if ($arUserField['USER_TYPE']['BASE_TYPE'] == 'enum') {
             $sType = 'int';
             if (is_callable(array($arUserField['USER_TYPE']['CLASS_NAME'], 'GetList'))) {
                 $rsEnum = call_user_func_array(array($arUserField['USER_TYPE']['CLASS_NAME'], 'GetList'), array($arUserField));
                 $obFieldValues = new CXMLCreator('CHOISES');
                 while ($ar = $rsEnum->GetNext()) {
                     $obFieldValue = new CXMLCreator('CHOISE', true);
                     $obFieldValue->setAttribute('id', $ar['ID']);
                     $obFieldValue->setData(htmlspecialcharsbx($ar['VALUE']));
                     $obFieldValues->addChild($obFieldValue);
                 }
             }
         } else {
             if ($arUserField['USER_TYPE']['BASE_TYPE'] == 'file') {
                 $sType = 'file';
             } else {
                 if ($arUserField['USER_TYPE']['BASE_TYPE'] == 'boolean') {
                     $sType = 'boolean';
                 } else {
                     if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'double' || $arUserField['USER_TYPE']['USER_TYPE_ID'] == 'integer') {
                         $sType = 'int';
                     } else {
                         if ($arUserField['USER_TYPE']['BASE_TYPE'] == 'datetime') {
                             $defVal = $arUserField['SETTINGS']['DEFAULT_VALUE']['VALUE'];
                             $sType = 'datetime';
                         } else {
                             if ($arUserField['USER_TYPE']['USER_TYPE_ID'] == 'string') {
                                 $sType = 'string';
                             } else {
                                 $sType = 'string';
                             }
                         }
                     }
                 }
             }
         }
         if (empty($defVal) && isset($arUserField['SETTINGS']['DEFAULT_VALUE']) && !is_array($arUserField['SETTINGS']['DEFAULT_VALUE'])) {
             $defVal = $arUserField['SETTINGS']['DEFAULT_VALUE'];
         }
         $obField = CXMLCreator::createTagAttributed('Field id="' . $FIELD_NAME . '" name="' . htmlspecialcharsbx($arUserField['EDIT_FORM_LABEL']) . '" type="' . $sType . '" default="' . $defVal . '" require="' . ($arUserField['MANDATORY'] == 'Y' ? 'true' : 'false') . '" multy="' . ($arUserField['MULTIPLE'] == 'Y' ? 'true' : 'false') . '"', '');
         if ($arUserField['USER_TYPE']['BASE_TYPE'] == 'enum' && $obFieldValues instanceof CXMLCreator) {
             $obField->addChild($obFieldValues);
             unset($obFieldValues);
         }
         $obFields->addChild($obField);
     }
 }
Exemple #12
0
 function UpdateListItems($listName, $updates)
 {
     global $USER;
     $arStatusValues = array_flip($this->arStatusValues);
     $arPriorityValues = array_flip($this->arPriorityValues);
     $arWeekDays = array_flip($this->arWeekDays);
     if (!($listName_original = CIntranetUtils::checkGUID($listName))) {
         return new CSoapFault('Data error', 'Wrong GUID - ' . $listName);
     }
     $obResponse = new CXMLCreator('Results');
     $listName = ToUpper(CIntranetUtils::makeGUID($listName_original));
     $obRes = CIBlockSection::GetList(array('SORT' => 'ASC'), array('XML_ID' => $listName_original));
     if (!($arSection = $obRes->Fetch())) {
         return new CSoapFault('List not found', 'List with ' . $listName . ' GUID is not found');
     }
     $bGroup = $arSection['SOCNET_GROUP_ID'] != '';
     if ($bGroup) {
         CModule::IncludeModule('socialnetwork');
         $arGroupTmp = CSocNetGroup::GetByID($arSection['SOCNET_GROUP_ID']);
         if ($arGroupTmp["CLOSED"] == "Y") {
             if (COption::GetOptionString("socialnetwork", "work_with_closed_groups", "N") != "Y") {
                 return new CSoapFault('Cannot modify archive group calendar', 'Cannot modify archive group calendar');
             }
         }
     }
     $obCalendar = new CEventCalendar();
     $obCalendar->Init(array('ownerType' => $bGroup ? 'GROUP' : 'USER', 'ownerId' => $bGroup ? $arSection['SOCNET_GROUP_ID'] : (is_object($USER) && $USER->GetID() ? $USER->GetID() : false), 'bOwner' => true, 'iblockId' => $arSection['IBLOCK_ID'], 'bCache' => false));
     // dirty hack
     $arPermissions = $obCalendar->GetPermissions(array('setProperties' => true));
     $obBatch = $updates->children[0];
     $atrONERROR = $obBatch->getAttribute('OnError');
     $atrDATEINUTC = $obBatch->getAttribute('DateInUtc');
     $atrPROPERTIES = $obBatch->getAttribute('Properties');
     $arChanges = $obBatch->children;
     $arResultIDs = array();
     $dateStart = ConvertTimeStamp(strtotime('-1 hour'), 'FULL');
     $arResponseRows = array();
     $arReplicationIDs = array();
     foreach ($arChanges as $obMethod) {
         $arData = array('_command' => $obMethod->getAttribute('Cmd'));
         foreach ($obMethod->children as $obField) {
             $name = $obField->getAttribute('Name');
             if ($name == 'MetaInfo') {
                 $name .= '_' . $obField->getAttribute('Property');
             }
             $arData[$name] = $obField->content;
         }
         if ($arData['_command'] == 'Delete') {
             $obRes = new CXMLCreator('Result');
             $obRes->setAttribute('ID', $obMethod->getAttribute('ID') . ',' . $arData['_command']);
             $obRes->setAttribute('List', $listName);
             $obRes->addChild($obNode = new CXMLCreator('ErrorCode'));
             if (CECEvent::Delete(array('id' => $arData['ID'], 'ownerType' => $bGroup ? 'GROUP' : 'USER', 'ownerId' => $bGroup ? $arSection['SOCNET_GROUP_ID'] : (is_object($USER) && $USER->GetID() ? $USER->GetID() : false), 'bOwner' => true, 'iblockId' => $arSection['IBLOCK_ID'], 'RMiblockId' => $this->__getRMIblockID(), 'allowResMeeting' => true))) {
                 CEventCalendar::ClearCache('/event_calendar/events/' . $arSection['IBLOCK_ID'] . '/');
                 $obNode->setData('0x00000000');
             } else {
                 $obNode->setData('0x81020014');
             }
             /*
             	0x00000000 - ok
             	0x81020015 - data conflict
             	0x81020014 - generic error such as invalid value for Field
             	0x81020016 - item does not exist
             */
             $obResponse->addChild($obRes);
         } elseif ($arData['_command'] == 'New' || $arData['_command'] == 'Update') {
             $q = ToLower($arData['Description']);
             if (($pos = strrpos($q, '</body>')) !== false) {
                 $arData['Description'] = substr($arData['Description'], 0, $pos);
             }
             if (($pos = strpos($q, '<body>')) !== false) {
                 $arData['Description'] = substr($arData['Description'], $pos + 6);
             }
             $arData['Description'] = str_replace('</DIV>', "\r\n</DIV>", $arData['Description']);
             $arData['Description'] = str_replace(array("&#10;", "&#13;"), "", $arData['Description']);
             $arData['Description'] = preg_replace("/<![^>]*>/", '', $arData['Description']);
             //$arData['Description'] = strip_tags($arData['Description']);
             $arData['Description'] = trim($arData['Description']);
             $arData['Location'] = trim($arData['Location']);
             $arData['EventDate'] = $this->__makeTS($arData['EventDate']);
             $arData['EndDate'] = $this->__makeTS($arData['EndDate']) + ($arData['fAllDayEvent'] ? -86340 : 0);
             $TZBias = intval(date('Z', $arData['EventDate']));
             $arData['EventType'] = intval($arData['EventType']);
             if ($arData['EventType'] == 2) {
                 $arData['EventType'] = 0;
             }
             if ($arData['EventType'] > 2) {
                 return new CSoapFault('Unsupported event type', 'Event type unsupported');
             }
             $arData['fRecurrence'] = intval($arData['fRecurrence']);
             if ($arData['RecurrenceData']) {
                 //$xmlstr = $arData['XMLTZone'];
                 //$arData['XMLTZone'] = new CDataXML();
                 //$arData['XMLTZone']->LoadString($xmlstr);
                 $xmlstr = $arData['RecurrenceData'];
                 $obRecurData = new CDataXML();
                 $obRecurData->LoadString($xmlstr);
                 /*
                 <recurrence>
                 		<rule>
                 			<firstDayOfWeek>mo</firstDayOfWeek>
                 			<repeat>
                 				<weekly mo='TRUE' tu='TRUE' th='TRUE' sa='TRUE' weekFrequency='1' />
                 			</repeat>
                 			<repeatForever>FALSE</repeatForever>
                 		</rule>
                 </recurrence>
                 <deleteExceptions>true</deleteExceptions>
                 */
                 $obRecurRule = $obRecurData->tree->children[0]->children[0];
                 $obRecurRepeat = $obRecurRule->children[1];
                 $obNode = $obRecurRepeat->children[0];
                 $arData['RecurrenceData'] = array();
                 switch ($obNode->name) {
                     case 'daily':
                         // hack. we have no "work days" daily recurence
                         if ($obNode->getAttribute('weekday') == 'TRUE') {
                             $arData['RecurrenceData']['PERIOD_TYPE'] = 'WEEKLY';
                             $arData['RecurrenceData']['PERIOD_ADDITIONAL'] = '0,1,2,3,4';
                             $arData['RecurrenceData']['PERIOD_COUNT'] = 1;
                         } else {
                             $arData['RecurrenceData']['PERIOD_TYPE'] = 'DAILY';
                             $arData['RecurrenceData']['PERIOD_COUNT'] = $obNode->getAttribute('dayFrequency');
                         }
                         $time_end = strtotime(date(date('Y-m-d', $arData['EventDate']) . ' H:i:s', $arData['EndDate']));
                         $arData['RecurrenceData']['EVENT_LENGTH'] = $time_end - $arData['EventDate'];
                         break;
                     case 'weekly':
                         $arData['RecurrenceData']['PERIOD_TYPE'] = 'WEEKLY';
                         $arData['RecurrenceData']['PERIOD_ADDITIONAL'] = '';
                         foreach ($arWeekDays as $day => $value) {
                             if ($obNode->getAttribute($day)) {
                                 $arData['RecurrenceData']['PERIOD_ADDITIONAL'] .= ($arData['RecurrenceData']['PERIOD_ADDITIONAL'] == '' ? '' : ',') . $value;
                             }
                         }
                         $arData['RecurrenceData']['PERIOD_COUNT'] = $obNode->getAttribute('weekFrequency');
                         $time_end = strtotime(date(date('Y-m-d', $arData['EventDate']) . ' H:i:s', $arData['EndDate']));
                         $arData['RecurrenceData']['EVENT_LENGTH'] = $time_end - $arData['EventDate'];
                         break;
                     case 'monthly':
                         $arData['RecurrenceData']['PERIOD_TYPE'] = 'MONTHLY';
                         $arData['RecurrenceData']['PERIOD_COUNT'] = $obNode->getAttribute('monthFrequency');
                         $time_end = strtotime(date(date('Y-m', $arData['EventDate']) . '-d H:i:s', $arData['EndDate']));
                         $arData['RecurrenceData']['EVENT_LENGTH'] = $time_end - $arData['EventDate'];
                         break;
                     case 'yearly':
                         $arData['RecurrenceData']['PERIOD_TYPE'] = 'YEARLY';
                         $arData['RecurrenceData']['PERIOD_COUNT'] = $obNode->getAttribute('yearFrequency');
                         $time_end = strtotime(date(date('Y', $arData['EventDate']) . '-m-d H:i:s', $arData['EndDate']));
                         $arData['RecurrenceData']['EVENT_LENGTH'] = $time_end - $arData['EventDate'];
                         break;
                 }
                 $obWhile = $obRule->children[2];
                 if ($obWhile->name == 'repeatForever') {
                     $arData['EndDate'] = MakeTimeStamp('');
                 } elseif ($obWhile->name == 'windowEnd') {
                     $arData['EndDate'] = $this->__makeTS($obWhile->textContent());
                 }
             }
             $TZBias = $arData['fAllDayEvent'] ? 0 : $TZBias;
             $arData['EventDate'] += $TZBias;
             $arData['EndDate'] += $TZBias;
             $arRes = array('iblockId' => $obCalendar->iblockId, 'ownerType' => $obCalendar->ownerType, 'ownerId' => $obCalendar->ownerId, 'RMiblockId' => $this->__getRMIblockID(), 'allowResMeeting' => true, 'bNew' => $arData['_command'] == 'New', 'fullUrl' => $obCalendar->fullUrl, 'userId' => $obCalendar->userId, 'pathToUserCalendar' => $obCalendar->pathToUserCalendar, 'pathToGroupCalendar' => $obCalendar->pathToGroupCalendar, 'userIblockId' => $obCalendar->userIblockId, 'calendarId' => $arSection['ID'], 'sectionId' => $arSection['IBLOCK_SECTION_ID'], 'dateFrom' => ConvertTimeStamp($arData['EventDate'], 'FULL'), 'dateTo' => ConvertTimeStamp($arData['EndDate'], 'FULL'), 'name' => $arData['Title'], 'desc' => $arData['Description'], 'prop' => array('ACCESSIBILITY' => $arStatusValues[$arData['MetaInfo_BusyStatus']], 'IMPORTANCE' => $arPriorityValues[$arData['MetaInfo_Priority']]), 'notDisplayCalendar' => true, 'location' => array('new' => CEventCalendar::ParseLocation($arData['Location'])));
             if ($arData['fRecurrence']) {
                 $arRes['prop']['PERIOD_TYPE'] = $arData['RecurrenceData']['PERIOD_TYPE'];
                 $arRes['prop']['PERIOD_COUNT'] = $arData['RecurrenceData']['PERIOD_COUNT'];
                 $arRes['prop']['EVENT_LENGTH'] = $arData['RecurrenceData']['EVENT_LENGTH'];
                 $arRes['prop']['PERIOD_ADDITIONAL'] = $arData['RecurrenceData']['PERIOD_ADDITIONAL'];
             }
             if ($arData['_command'] == 'New') {
                 $arRes['bNew'] = true;
             } else {
                 $arRes['id'] = $arData['ID'];
             }
             if (!$arRes['bNew']) {
                 if ($arOldEvent = $obCalendar->GetEvents(array('ownerType' => 'USER', 'ownerId' => $arSection['CREATED_BY'], 'bOwner' => true, 'iblockId' => $arSection['IBLOCK_ID'], 'sectionId' => $arSection['ID'], 'eventId' => $arRes['id'], 'arCalendarIds' => array($arSection['ID']), 'forExport' => true))) {
                     $arOldEvent = $arOldEvent[0];
                     $arRes['prop']['VERSION'] = $arOldEvent['VERSION'];
                     if ($arOldEvent['LOCATION']) {
                     }
                     $arRes['location']['old'] = CEventCalendar::ParseLocation($arOldEvent['LOCATION']);
                     if ($arRes['location']['old']['mrid']) {
                         $arRes['location']['new'] = 'ECMR_' . $arRes['location']['old']['mrid'];
                         $arRes['prop']['VERSION']++;
                     }
                     $bMaster = true;
                     if (is_array($arOldEvent['GUESTS']) && count($arOldEvent['GUESTS']) > 0) {
                         $arRes['GUESTS'] = array();
                         foreach ($arOldEvent['GUESTS'] as $arGuest) {
                             $arRes['GUESTS'][] = $arGuest['id'];
                         }
                     }
                     if (is_array($arOldEvent['HOST'])) {
                         $bMaster = false;
                         $arRes['prop']['PARENT'] = $arOldEvent['HOST']['parentId'];
                     }
                     if (!$bMaster) {
                         $arRes['name'] = $arOldEvent['NAME'];
                         $arRes['desc'] = $arOldEvent['DETAIL_TEXT'];
                         $arRes['dateFrom'] = $arOldEvent['DATE_FROM'];
                         $arRes['dateTo'] = $arOldEvent['DATE_TO'];
                         if (is_array($arOldEvent['PERIOD'])) {
                             $arRes['prop']['PERIOD_TYPE'] = $arOldEvent['PERIOD']['TYPE'];
                             $arRes['prop']['PERIOD_COUNT'] = $arOldEvent['PERIOD']['COUNT'];
                             $arRes['prop']['EVENT_LENGTH'] = $arOldEvent['PERIOD']['LENGTH'];
                             $arRes['prop']['PERIOD_ADDITIONAL'] = $arOldEvent['PERIOD']['DAYS'];
                         } else {
                             unset($arRes['prop']['PERIOD_TYPE']);
                             unset($arRes['prop']['PERIOD_COUNT']);
                             unset($arRes['prop']['EVENT_LENGTH']);
                             unset($arRes['prop']['PERIOD_ADDITIONAL']);
                         }
                     } else {
                         if (is_array($arOldEvent['PERIOD']) && !$arData['RecurrenceData'] && $arData['EventType'] == 1) {
                             $arRes['dateFrom'] = $arOldEvent['DATE_FROM'];
                             $arRes['dateTo'] = $arOldEvent['DATE_TO'];
                             $arRes['prop']['PERIOD_TYPE'] = $arOldEvent['PERIOD']['TYPE'];
                             $arRes['prop']['PERIOD_COUNT'] = $arOldEvent['PERIOD']['COUNT'];
                             $arRes['prop']['EVENT_LENGTH'] = $arOldEvent['PERIOD']['LENGTH'];
                             $arRes['prop']['PERIOD_ADDITIONAL'] = $arOldEvent['PERIOD']['DAYS'];
                         }
                     }
                 } else {
                     return new CSoapFault('Event not found', 'Event ' . $arRes['id'] . ' not found on server');
                 }
             }
             if (is_array($arRes['location']['old'])) {
                 $arRes['location']['old'] = $arRes['location']['old']['str'];
             }
             if (is_array($arRes['location']['new'])) {
                 $arRes['location']['new'] = $arRes['location']['new']['str'];
             }
             if ($EventID = $obCalendar->SaveEvent($arRes)) {
                 CEventCalendar::ClearCache('/event_calendar/events/' . $arRes['iblockId'] . '/');
                 // dirty hack
                 $arReplicationIDs[$EventID] = $arData['MetaInfo_ReplicationID'];
                 $arResponseRows[$EventID] = new CXMLCreator('Result');
                 $arResponseRows[$EventID]->setAttribute('ID', $obMethod->getAttribute('ID') . ',' . $arData['_command']);
                 $arResponseRows[$EventID]->setAttribute('List', $listName);
                 $arResponseRows[$EventID]->addChild($obNode = new CXMLCreator('ErrorCode'));
                 $obNode->setData('0x00000000');
                 //$arResponseRows[$EventID]->setAttribute('Version', 3);
             }
         }
     }
     $arMethodParams = array('ownerType' => 'USER', 'ownerId' => is_object($USER) && $USER->GetID() ? $USER->GetID() : false, 'iblockId' => $arSection['IBLOCK_ID'], 'sectionId' => $arSection['ID'], 'arCalendarIds' => array($arSection['ID']), 'forExport' => true, 'bLoadAll' => false, 'timestampFrom' => $dateStart);
     $arCalendarEntries = $obCalendar->GetEvents($arMethodParams);
     foreach ($arCalendarEntries as $arEntry) {
         if ($arResponseRows[$arEntry['ID']]) {
             $obRow = $this->__getRow($arEntry, $listName, $last_change = 0);
             $obRow->setAttribute('xmlns:z', "#RowsetSchema");
             if ($arReplicationIDs[$arEntry['ID']]) {
                 $obRow->setAttribute('MetaInfo_ReplicationID', $arReplicationIDs[$arEntry['ID']]);
             }
             $arResponseRows[$arEntry['ID']]->addChild($obRow);
         }
         $obResponse->addChild($arResponseRows[$arEntry['ID']]);
     }
     return array('UpdateListItemsResult' => $obResponse);
 }