/** * Replace old tags with new one and delete old ones * * @param mixed $system * @param mixed $tag_ids - to be replaced and deleted * @param mixed $tag_id_new * @param mixed $ugrID */ function tagReplace($system, $tag_ids, $tag_id_new, $ugrID = null) { $ugrID = $system->is_admin2($ugrID); if (!$ugrID) { $system->addError(HEURIST_REQUEST_DENIED); return false; } else { if (is_string($tag_ids)) { $tag_ids = explode(",", $tag_ids); } if (is_array($tag_ids) && count($tag_ids) > 0 && intval($tag_id_new)) { $mysqli = $system->get_mysqli(); $query = 'select count(*) from usrTags where tag_ID in (' . $tag_id_new . ',' . implode(', ', $tag_ids) . ') and tag_UGrpID=' . $ugrID; $cnt = mysql__select_value($mysqli, $query); if ($cnt != count($tag_ids) + 1) { $system->addError(HEURIST_INVALID_REQUEST, "Not found all tags"); return false; } //add new links $query = 'insert ignore into usrRecTagLinks (rtl_RecID, rtl_TagID) ' . 'select distinct rtl_RecId, ' . $tag_id_new . ' from usrRecTagLinks where rtl_TagID in (' . implode(', ', $tag_ids) . ')'; $res = $mysqli->query($query); $res = $mysqli->query($query); if ($res) { $cnt = $mysqli->affected_rows; //delete old ones $res = tagDelete($system, $tag_ids, $ugrID); if (is_numeric($res) && $res > 0) { return array('tags_deleted' => $res, 'taglinks_replased' => $cnt); } else { return false; } } else { $system->addError(HEURIST_DB_ERROR, "Cannot replace tag links", $mysqli->error); return false; } } else { $system->addError(HEURIST_INVALID_REQUEST); return false; } } }
} else { $mysqli = $system->get_mysqli(); if ($system->get_user_id() < 1) { $response = $system->addError(HEURIST_REQUEST_DENIED); } else { $action = @$_REQUEST['a']; // || @$_REQUEST['action']; // call function from db_record library // these function returns standard response: status and data // data is recordset (in case success) or message $res = false; if ($action == "add" || $action == "save") { $res = tagSave($system, $_REQUEST); } else { if ($action == "delete" && @$_REQUEST['ids']) { $res = tagDelete($system, $_REQUEST['ids'], @$_REQUEST['UGrpID']); } else { if ($action == "search" && @$_REQUEST['UGrpID']) { $res = tagGetByRecords($system, @$_REQUEST['info'] != "short", @$_REQUEST['recIDs'], @$_REQUEST['UGrpID']); if (is_array($res)) { $res['recIDs'] = @$_REQUEST['recIDs']; } /* $res = tagGetByUser($system, false, $_REQUEST['UGrpID']); */ } else { if ($action == "replace" && @$_REQUEST['UGrpID']) { $res = tagReplace($system, $_REQUEST['ids'], $_REQUEST['new_id'], @$_REQUEST['UGrpID']); } else { if ($action == "rating") { $res = bookmarkRating($system, @$_REQUEST['recIDs'], @$_REQUEST['rating'], @$_REQUEST['UGrpID']);