Ejemplo n.º 1
0
	global $DB;

	// group UPDATE
	if($lAdmin->EditAction() && $userIsAdmin)
	{
		foreach($FIELDS as $id => $arFields)
		{
			$DB->StartTransaction();

			if(!$lAdmin->IsUpdated($id)) // if there were no data change on this row - do nothing with it
				continue;

			try
			{
				$res = Helper::update($id, $arFields, true);

				if(!empty($res['errors']))
				{
					foreach($res['errors'] as &$error)
						$error = '  '.$error;
					unset($error);

					throw new Main\SystemException(implode(',<br />', $res['errors']));
				}
			}
			catch(Main\SystemException $e)
			{
				// todo: do smth
				$lAdmin->AddUpdateError(Loc::getMessage('SALE_LOCATION_L_ITEM_SAVE_ERROR', array('#ITEM#' => $id)).": <br />".$e->getMessage().'<br />', $id);
				$DB->Rollback();
Ejemplo n.º 2
0
 /**
  * Function makes some actions based on what is in $this->request
  * @return void
  */
 protected function performAction()
 {
     $requestMethod = \Bitrix\Main\Context::getCurrent()->getServer()->getRequestMethod();
     $this->componentData['FORM_ROWS'] = Helper::getDetailPageRows();
     $this->dbResult['CALCULATED_BACK_URL'] = false;
     if (strlen($this->dbResult['REQUEST']['GET']['return_url'])) {
         $this->dbResult['SPECIFIED_BACK_URL'] = $this->dbResult['REQUEST']['GET']['return_url'];
         $this->dbResult['CALCULATED_BACK_URL'] = $this->dbResult['REQUEST']['GET']['return_url'];
     }
     if (check_bitrix_sessid()) {
         $actionSave = $requestMethod == 'POST' && isset($this->dbResult['REQUEST']['POST']['save']);
         $actionApply = $requestMethod == 'POST' && isset($this->dbResult['REQUEST']['POST']['apply']);
         $actionDelete = $requestMethod == 'GET' && isset($this->dbResult['REQUEST']['GET']['delete']);
         $id = isset($this->dbResult['REQUEST']['POST']['loc_id']) ? intval($this->dbResult['REQUEST']['POST']['loc_id']) : 0;
         if ($id <= 0 && isset($this->dbResult['REQUEST']['POST']['ID'])) {
             $id = intval($this->dbResult['REQUEST']['POST']['ID']) > 0 ? intval($this->dbResult['REQUEST']['POST']['ID']) : 0;
         }
         $res = false;
         if ($actionSave || $actionApply) {
             if ($id) {
                 $res = Helper::update($id, $this->dbResult['REQUEST']['POST']);
             } else {
                 $res = Helper::add($this->dbResult['REQUEST']['POST']);
                 $id = $res['id'];
             }
         } elseif ($actionDelete) {
             $locID = isset($this->arParams['LOC_ID']) ? intval($this->arParams['LOC_ID']) : 0;
             if ($locID) {
                 $res = Location\LocationTable::getById($locID)->fetch();
                 $parentOfDeleted = intval($res['PARENT_ID']);
                 $res = Helper::delete($locID);
             }
         }
         if ($res !== false) {
             if (!$res['success']) {
                 $this->errors['NONFATAL'] = array_merge($this->errors['NONFATAL'], $res['errors']);
                 $this->componentData['ACTION_FAILURE'] = true;
             } else {
                 $url = $this->dbResult['CALCULATED_BACK_URL'];
                 if ($actionApply) {
                     $url = false;
                 } else {
                     if ($actionSave) {
                         // get parent (only for locations)
                         $res = Location\LocationTable::getById($id)->fetch();
                         if (!$url) {
                             $url = CComponentEngine::MakePathFromTemplate($this->arParams['PATH_TO_LOCATIONS_LIST']) . '?PARENT_ID=' . intval($res['PARENT_ID']);
                         }
                     } elseif ($actionDelete) {
                         if (!$url) {
                             $url = CComponentEngine::MakePathFromTemplate($this->arParams['PATH_TO_LOCATIONS_LIST']) . '?PARENT_ID=' . intval($parentOfDeleted);
                         }
                     }
                 }
                 if ($url) {
                     LocalRedirect($url);
                 }
             }
         }
     }
 }
		$saveAsId = intval($_REQUEST['element']['ID']);

		global $DB;
		$redirectUrl = false;

		// parent id might be updated, so re-read it from request
		if(intval($_REQUEST['PARENT_ID']))
			$parentId = intval($_REQUEST['PARENT_ID']);

		try
		{
			$DB->StartTransaction();

			if($saveAsId) // existed, updating
			{
				$res = Helper::update($saveAsId, $_REQUEST['element']);

				if($res['success']) // on successfull update ...
				{
					if($actionSave)
						$redirectUrl = $returnUrl ? $returnUrl : Helper::getListUrl($parentId); // go to the parent page
			
					// $actionApply : do nothing
				}
			}
			else // new or copyed item
			{
				$res = Helper::add($_REQUEST['element']);
				if($res['success']) // on successfull add ...
				{
					if($actionSave)
	global $DB;

	// group UPDATE
	if($lAdmin->EditAction() && $userIsAdmin)
	{
		foreach($FIELDS as $id => $arFields)
		{
			$DB->StartTransaction();

			if(!$lAdmin->IsUpdated($id)) // if there were no data change on this row - do nothing with it
				continue;

			try
			{
				$res = Helper::update($id, $arFields);

				if(!empty($res['errors']))
				{
					foreach($res['errors'] as &$error)
						$error = '&nbsp;&nbsp;'.$error;
					unset($error);

					throw new Main\SystemException(implode(',<br />', $res['errors']));
				}
			}
			catch(Main\SystemException $e)
			{
				// todo: do smth
				$lAdmin->AddUpdateError(Loc::getMessage('SALE_LOCATION_L_ITEM_SAVE_ERROR', array('#ITEM#' => $id)).": <br />".$e->getMessage().'<br />', $id);
				$DB->Rollback();