]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
collection management can update the entries with the rights of the collection
authorBanana <mail@bananas-playground.net>
Fri, 8 Jan 2021 10:30:39 +0000 (11:30 +0100)
committerBanana <mail@bananas-playground.net>
Fri, 8 Jan 2021 10:30:39 +0000 (11:30 +0100)
CHANGELOG
webclient/lib/managecollections.class.php
webclient/view/default/managecolletions/managecolletions.html
webclient/view/default/managecolletions/managecolletions.php

index c6c3032be430c7c47e469e6a2393cbebfbf4afee..0bc865fc24425340143a59f390f1d7eaa168d955 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,11 +3,12 @@
        * Missing changelog file
        * api has its own log file now.
        * User profile for editing own settings.
+       * Collection management has the option to update entry rights with the collection ones.
 
 1.0 - Castle 20210106
        * First usable version
        * Using as a collection management software will work
-       * Rights management needs tweeking, so use the admin account for a start
+       * Rights management needs tweaking, so use the admin account for a start
        * Documentation covers the basics
        * Use it and give feedback.
        * Also, make backups.
index a31328e159f92f82afee4ecc655915392efb36ed..fc6b86ea4c778139b3ba74fa6592037b7f819835 100644 (file)
@@ -329,6 +329,9 @@ class ManageCollections {
                        try {
                                $this->_DB->query($queryStr);
                                $this->_updateToolRelation($data['id'],$data['tool']);
+                               if($data['doRightsForEntries'] === true) {
+                                       $this->_updateEntryRights($data['id'], $data['owner'], $data['group'], $data['rights']);
+                               }
                                $ret = true;
                        }
                        catch (Exception $e) {
@@ -536,11 +539,37 @@ class ManageCollections {
                        }
                        $this->_DB->commit();
                        $ret = true;
-               } catch (Exception $e) {
+               }
+               catch (Exception $e) {
                        $this->_DB->rollback();
                        error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
                }
 
                return $ret;
        }
+
+       private function _updateEntryRights($collectionId, $owner=false, $group=false, $rights=false) {
+               if(!empty($collectionId)) {
+                       $queryStr = "UPDATE `".DB_PREFIX."_collection_entry_".$collectionId."` SET";
+
+                       if(Summoner::validate($owner, "digit")) {
+                               $queryStr .= " `owner` = '".$this->_DB->real_escape_string($owner)."',";
+                       }
+                       if(Summoner::validate($group, "digit")) {
+                               $queryStr .= " `group` = '".$this->_DB->real_escape_string($group)."',";
+                       }
+                       if(Summoner::validate($rights, "rights")) {
+                               $queryStr .= " `rights` = '".$this->_DB->real_escape_string($rights)."',";
+                       }
+                       $queryStr = trim($queryStr, ",");
+
+                       if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
+                       try {
+                               $this->_DB->query($queryStr);
+                       }
+                       catch (Exception $e) {
+                               error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
+                       }
+               }
+       }
 }
index 486957f3a337d4c46300fad5380077c4c2477226..a127e55ec4aee6ce759a42c908a2e50d1dd12d71 100644 (file)
                                                   value="<?php echo Summoner::ifset($TemplateData['editData'], 'description'); ?>">
                                </div>
                        </div>
+                       <div class="uk-margin">
+                               <label class="uk-form-label" for="defaultSearchField">Default global search field</label>
+                               <div class="uk-form-controls">
+                                       <select class="uk-select" id="defaultSearchField" name="fdata[defaultSearchField]">
+                                               <option value="">Please select</option>
+                                               <?php foreach($TemplateData['existingFields'] as $k=>$v) { ?>
+                                               <option value="<?php echo $v['identifier']; ?>"
+                                               <?php if(Summoner::ifsetValue($TemplateData['editData'], 'defaultSearchField', $v['identifier'])) echo 'selected'; ?>
+                                               ><?php echo $v['displayname']; ?> (<?php echo $v['type']; ?>)</option>
+                                               <?php } ?>
+                                       </select>
+                                       <small>The field is used in the global search.
+                                               <span class="" uk-icon="icon: warning"></span> Altering the default search field results in
+                                               a DB reindex. This could take some time, depending on the amount of data.</small>
+                               </div>
+                       </div>
+                       <div class="uk-margin">
+                               <label class="uk-form-label" for="tool">Tools</label>
+                               <div class="uk-form-controls">
+                                       <select class="uk-select" id="tool" name="fdata[tool][]" multiple="multiple" size="5">
+                                               <option value="">None</option>
+                                               <?php foreach($TemplateData['toolSelection'] as $k=>$v) { ?>
+                                               <option value="<?php echo $k; ?>"
+                                               <?php if(Summoner::ifset($TemplateData['editData']['tool'],$k)) echo 'selected'; ?>
+                                               ><?php echo $v['name']; ?> (<?php echo $v['description']; ?>)</option>
+                                               <?php } ?>
+                                       </select>
+                               </div>
+                       </div>
+                       <hr class="uk-margin-large">
                        <div class="uk-margin">
                                <label class="uk-form-label" for="owner">Owner</label>
                                <div class="uk-form-controls">
                                        </table>
                                </div>
                        </div>
+                       <?php if(Summoner::ifset($TemplateData['editData'], 'name')) { ?>
                        <div class="uk-margin">
-                               <label class="uk-form-label" for="tool">Tools</label>
-                               <div class="uk-form-controls">
-                                       <select class="uk-select" id="tool" name="fdata[tool][]" multiple="multiple" size="5">
-                                               <option value="">None</option>
-                                               <?php foreach($TemplateData['toolSelection'] as $k=>$v) { ?>
-                                               <option value="<?php echo $k; ?>"
-                                               <?php if(Summoner::ifset($TemplateData['editData']['tool'],$k)) echo 'selected'; ?>
-                                               ><?php echo $v['name']; ?> (<?php echo $v['description']; ?>)</option>
-                                               <?php } ?>
-                                       </select>
+                               <div class="uk-form-label">Update entry with collection rights</div>
+                               <div class="uk-form-controls uk-form-controls-text">
+                                       <label>
+                                               <input class="uk-checkbox" type="checkbox" name="fdata[doRightsForEntries]" value="1">
+                                               Warning: This will overwrite existing entry rights (user, group, rights) with the ones from the collection!
+                                       </label>
                                </div>
                        </div>
-                       <?php if(Summoner::ifset($TemplateData['editData'], 'name')) { ?>
                        <div class="uk-margin">
                                <div class="uk-form-label">Delete <span uk-icon="warning"></span></div>
                                <div class="uk-form-controls uk-form-controls-text">
                                        <label>
                                                <input class="uk-checkbox" type="checkbox" name="fdata[doDelete]" value="1">
-                                               Warning: this will delete ALL the data in this collection!
+                                               Warning: This will delete ALL the data in this collection!
                                        </label>
                                </div>
                        </div>
                        <?php } ?>
-                       <div class="uk-margin">
-                               <label class="uk-form-label" for="defaultSearchField">Default global search field</label>
-                               <div class="uk-form-controls">
-                                       <select class="uk-select" id="defaultSearchField" name="fdata[defaultSearchField]">
-                                               <option value="">Please select</option>
-                                               <?php foreach($TemplateData['existingFields'] as $k=>$v) { ?>
-                                               <option value="<?php echo $v['identifier']; ?>"
-                                               <?php if(Summoner::ifsetValue($TemplateData['editData'], 'defaultSearchField', $v['identifier'])) echo 'selected'; ?>
-                                               ><?php echo $v['displayname']; ?> (<?php echo $v['type']; ?>)</option>
-                                               <?php } ?>
-                                       </select>
-                                       <small>The field is used in the global search.
-                                       <span class="" uk-icon="icon: warning"></span> Altering the default search field results in
-                                       a DB reindex. This could take some time, depending on the amount of data.</small>
-                               </div>
-                       </div>
                        <div class="uk-margin">
                                <button class="uk-button uk-button-primary" type="submit" name="submitForm">
                                        Save
index dbc965ec6d4df682697826651f4ea8b957611b98..b029a3bdbb79c3632216d63868fae3cac9108263 100644 (file)
@@ -71,6 +71,11 @@ if(isset($_POST['submitForm'])) {
                        $_saveData['tool'] = $fdata['tool'];
                }
 
+               $_saveData['doRightsForEntries'] = false;
+               if(isset($fdata['doRightsForEntries'])) {
+                       $_saveData['doRightsForEntries'] = true;
+               }
+
                if(!empty($TemplateData['editData']['name'])) { // EDIT
                        if(isset($fdata['doDelete'])) {
                                $do = $ManangeCollections->deleteCollection($_id);