Esempio n. 1
0
         $arFilesToUnlink = array();
         foreach ($_POST["FILES_TO_DELETE"] as $file) {
             if (in_array($file, $arData["FILES"])) {
                 // Skip files, that attached to some existing tasks
                 $rsFiles = CTaskFiles::GetList(array(), array('FILE_ID' => $file));
                 // There is no tasks with this file, so it can be removed
                 if (!($arFile = $rsFiles->Fetch())) {
                     $arFilesToUnlink[] = $file;
                 }
             }
         }
         foreach ($arFilesToUnlink as $file) {
             CFile::Delete($file);
         }
     }
     $result = $template->Update($arParams["TEMPLATE_ID"], $arFields, array('CHECK_RIGHTS_ON_FILES' => true, 'USER_ID' => (int) $USER->getId()));
     $templateID = $arParams["TEMPLATE_ID"];
 } else {
     $templateID = $result = $template->Add($arFields, array('CHECK_RIGHTS_ON_FILES' => true, 'USER_ID' => (int) $USER->getId()));
 }
 // format check list items
 if (is_array($_POST['CHECKLIST_ITEM_ID'])) {
     $sort = 0;
     $items = array();
     foreach ($_POST['CHECKLIST_ITEM_ID'] as $clId) {
         if ((string) $_POST['CHECKLIST_ITEM_TITLE'][$clId]) {
             $id = (string) $clId === (string) intval($clId) ? intval($clId) : false;
             $data = array('TEMPLATE_ID' => $templateID, 'TITLE' => $_POST['CHECKLIST_ITEM_TITLE'][$clId], 'CHECKED' => $_POST['CHECKLIST_ITEM_IS_CHECKED'][$clId] == 'Y', 'SORT' => $sort++);
             if (intval($id)) {
                 $data['ID'] = $id;
                 $items[$id] = $data;