Changeset 16485
- Timestamp:
- 05/28/08 14:05:48 (5 months ago)
- Files:
-
- trunk/midcom/midcom.helper.datamanager2/config/config.inc (modified) (1 diff)
- trunk/midcom/midcom.helper.datamanager2/config/manifest.inc (modified) (1 diff)
- trunk/midcom/midcom.helper.datamanager2/controller.php (modified) (4 diffs)
- trunk/midcom/midcom.helper.datamanager2/controller/ajax.php (modified) (4 diffs)
- trunk/midcom/midcom.helper.datamanager2/controller/simple.php (modified) (4 diffs)
- trunk/midcom/midcom.helper.datamanager2/documentation/CHANGES (modified) (1 diff)
- trunk/midcom/midcom.helper.datamanager2/formmanager.php (modified) (1 diff)
- trunk/midcom/midcom.helper.datamanager2/locale/default.en.txt (modified) (8 diffs)
- trunk/midcom/midcom.helper.datamanager2/locale/default.fi.txt (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/midcom/midcom.helper.datamanager2/config/config.inc
r16421 r16485 126 126 ), 127 127 'fck_default_config_snippet' => 'file://midcom/helper/datamanager2/config/fckeditor_default.inc', 128 129 // Lock timeout, which defines how many seconds the object should be locked 130 'lock_timeout' => 1800, trunk/midcom/midcom.helper.datamanager2/config/manifest.inc
r15038 r16485 3 3 'state' => 'beta', 4 4 'purecode' => true, 5 'privileges' => array 6 ( 7 'break_lock' => 'midcom.helper.datamanager2:break_lock', 8 ), 5 9 'package.xml' => array 6 10 ( trunk/midcom/midcom.helper.datamanager2/controller.php
r14381 r16485 61 61 var $formmanager = null; 62 62 63 /** 64 * Lock timeout defines the length of lock in seconds. 65 * 66 * @access public 67 * @var integer 68 */ 69 var $lock_timeout = null; 63 70 64 71 /** … … 69 76 $this->_component = 'midcom.helper.datamanager2'; 70 77 parent::midcom_baseclasses_components_purecode(); 71 72 78 } 73 79 … … 79 85 function initialize() 80 86 { 87 if (is_null($this->lock_timeout)) 88 { 89 $this->lock_timeout = (int) $this->_config->get('lock_timeout'); 90 } 91 81 92 return true; 82 93 } … … 243 254 function display_form() 244 255 { 256 if (midcom_helper_datamanager2_controller::is_locked($this->datamanager->storage->object, $this->lock_timeout)) 257 { 258 $this->show_remove_lock(); 259 return; 260 } 261 245 262 $this->formmanager->display_form(); 246 263 } 264 265 /** 266 * Show the lock status 267 * 268 * @access public 269 */ 270 function show_remove_lock() 271 { 272 if ( function_exists('mgd_is_element_loaded') 273 && mgd_is_element_loaded('midcom_helper_datamanager2_remove_lock')) 274 { 275 mgd_show_element('midcom_helper_datamanager2_remove_lock'); 276 } 277 else 278 { 279 $user = $this->datamanager->storage->object->get_parameter('midcom.helper.datamanager2.lock', 'user'); 280 $expires = strtotime($this->datamanager->storage->object->get_parameter('midcom.helper.datamanager2.lock', 'expires')); 281 282 $person = new midcom_db_person($user); 283 ?> 284 <div class="midcom_helper_datamanager2_remove_lock"> 285 <h2><?php echo $this->_l10n->get('object locked'); ?></h2> 286 <p> 287 <?php echo sprintf($this->_l10n->get('this object was locked by %s'), $person->name); ?>. 288 <?php echo sprintf($this->_l10n->get('lock will expire on %s'), strftime('%x %X', $expires)); ?>. 289 </p> 290 <?php 291 if ($_MIDCOM->auth->can_user_do('midcom.helper.datamanager2:break_lock', null, 'midcom_helper_datamanager2_controller', 'midcom.helper.datamanager2')) 292 { 293 echo "<form method=\"post\">\n"; 294 echo " <p class=\"break_lock\">\n"; 295 echo " <input type=\"hidden\" name=\"midcom_helper_datamanager2_object\" value=\"{$this->datamanager->storage->object->guid}\" />\n"; 296 echo " <input type=\"submit\" name=\"midcom_helper_datamanager2_remove_lock\" value=\"" . $this->_l10n->get('break the lock') . "\" class=\"break_lock\" />\n"; 297 echo " </p>\n"; 298 echo "</form>\n"; 299 } 300 ?> 301 </div> 302 <?php 303 } 304 } 305 306 /** 307 * Check if the object is being edited elsewhere 308 * 309 * @static 310 * @access public 311 * @param mixed $guid Object or GUID of the object 312 * @return boolean True if the object is locked 313 */ 314 function is_locked($target, $timeout = 0) 315 { 316 // Remove the object lock if applicable 317 if ( isset($_REQUEST['midcom_helper_datamanager2_remove_lock']) 318 && isset($_REQUEST['midcom_helper_datamanager2_object'])) 319 { 320 // Get the object 321 $object = $_MIDCOM->dbfactory->get_object_by_guid($_POST['midcom_helper_datamanager2_object']); 322 323 // Remove the lock, if permission is granted 324 if ($_MIDCOM->auth->can_user_do('midcom.helper.datamanager2:break_lock', null, 'midcom_helper_datamanager2_controller', 'midcom.helper.datamanager2')) 325 { 326 midcom_helper_datamanager2_controller::set_lock($object, $timeout); 327 } 328 else 329 { 330 $_MIDCOM->uimessages->add($_MIDCOM->i18n->get_string('midcom.helper.datamanager2', 'midcom.helper.datamanager2'), $_MIDCOM->i18n->get_string('permission denied', 'midcom'), 'error'); 331 } 332 } 333 334 // Check that we have an object at disposal 335 if (is_object($target)) 336 { 337 $object =& $target; 338 } 339 else 340 { 341 $object = $_MIDCOM->dbfactory->get_object_by_guid($target); 342 } 343 344 // Couldn't get the object. Different error handling here? Controller should have already alarmed the user, though... 345 if ( !$object 346 || !$object->guid) 347 { 348 return false; 349 } 350 351 $expires = (int) strtotime($object->get_parameter('midcom.helper.datamanager2.lock', 'expires')); 352 353 // Object not locked, allow editing 354 if (!$expires) 355 { 356 return false; 357 } 358 359 // Get the person who locked the object 360 $user = $object->get_parameter('midcom.helper.datamanager2.lock', 'user'); 361 362 // Lock was created by the user, allow unquestionable editing 363 if ( isset($_MIDCOM->auth->user) 364 && isset($_MIDCOM->auth->user->guid) 365 && $user === $_MIDCOM->auth->user->guid) 366 { 367 return false; 368 } 369 370 // Object lock is no longer valid 371 if (time() > $expires) 372 { 373 return false; 374 } 375 376 // Lock checked, object locked 377 return true; 378 } 379 380 /** 381 * Set the object lock 382 * 383 * @static 384 * @access public 385 * @param mixed $object Object that should be locked 386 * @param int $timeout Length of the lock timeout 387 */ 388 function set_lock($object, $timeout) 389 { 390 if ((int) $timeout < 1) 391 { 392 $object->set_parameter('midcom.helper.datamanager2.lock', 'user', ''); 393 $object->set_parameter('midcom.helper.datamanager2.lock', 'expires', ''); 394 return true; 395 } 396 397 $object->set_parameter('midcom.helper.datamanager2.lock', 'user', $_MIDCOM->auth->user->guid); 398 $object->set_parameter('midcom.helper.datamanager2.lock', 'expires', strftime('%Y-%m-%d %H:%M:%S', time() + $timeout)); 399 400 return true; 401 } 247 402 } 403 ?> trunk/midcom/midcom.helper.datamanager2/controller/ajax.php
r16373 r16485 28 28 29 29 /** 30 * AJAX controller initialization. Loads required Javascript libraries 30 * AJAX controller initialization. Loads required Javascript libraries and connects to the parent class initialization. 31 31 * 32 32 * @return boolean Indicating success. … … 34 34 function initialize() 35 35 { 36 parent::initialize(); 37 36 38 if (count($this->schemadb) == 0) 37 39 { … … 286 288 $result = $this->formmanager->process_form(); 287 289 290 // Remove the lock 291 if ( $result === 'save' 292 || $result === 'cancel') 293 { 294 midcom_helper_datamanager2_controller::set_lock($this->datamanager->storage->object, 0); 295 } 296 // or set it, if needed 297 elseif (!midcom_helper_datamanager2_controller::is_locked($this->datamanager->storage->object, $this->lock_timeout)) 298 { 299 midcom_helper_datamanager2_controller::set_lock($this->datamanager->storage->object, $this->lock_timeout); 300 } 301 288 302 // Handle successful save explicitly. 289 303 if ( $result == 'save' … … 326 340 return $result; 327 341 } 328 329 342 } 330 331 343 ?> trunk/midcom/midcom.helper.datamanager2/controller/simple.php
r16373 r16485 23 23 { 24 24 /** 25 * Empty default implementation, this calls won't do much.25 * Check if a schema has been set 26 26 * 27 27 * @return boolean Indicating success. … … 29 29 function initialize() 30 30 { 31 parent::initialize(); 32 31 33 if (count($this->schemadb) == 0) 32 34 { … … 86 88 $result = $this->formmanager->process_form(); 87 89 90 // Remove the lock 91 if ( $result === 'save' 92 || $result === 'cancel') 93 { 94 midcom_helper_datamanager2_controller::set_lock($this->datamanager->storage->object, 0); 95 } 96 // or set it, if needed 97 elseif (!midcom_helper_datamanager2_controller::is_locked($this->datamanager->storage->object, $this->lock_timeout)) 98 { 99 midcom_helper_datamanager2_controller::set_lock($this->datamanager->storage->object, $this->lock_timeout); 100 } 101 88 102 // Handle successful save explicitly. 89 103 if ( $result == 'save' … … 131 145 return $result; 132 146 } 133 134 147 } 135 136 148 ?> trunk/midcom/midcom.helper.datamanager2/documentation/CHANGES
r14891 r16485 8 8 which might even break existing functionality. 9 9 - All items marked with "+" represent completely new features. 10 11 2008-05-28 adrenalin 12 + Added locking feature for disabling simultaneous editing 10 13 11 14 2008-02-12 adrenalin trunk/midcom/midcom.helper.datamanager2/formmanager.php
r16300 r16485 1000 1000 function get_clicked_button() 1001 1001 { 1002 if (array_key_exists('midcom_helper_datamanager2_save', $_REQUEST)) 1003 { 1004 return 'save'; 1005 } 1006 else if (array_key_exists('midcom_helper_datamanager2_next', $_REQUEST)) 1007 { 1008 return 'next'; 1009 } 1010 else if (array_key_exists('midcom_helper_datamanager2_previous', $_REQUEST)) 1011 { 1012 return 'previous'; 1013 } 1014 else if (array_key_exists('midcom_helper_datamanager2_cancel', $_REQUEST)) 1015 { 1016 return 'cancel'; 1017 } 1018 else if (array_key_exists('midcom_helper_datamanager2_preview', $_REQUEST)) 1019 { 1020 return 'preview'; 1021 } 1022 else 1023 { 1024 return 'edit'; 1025 } 1026 } 1027 1002 switch (true) 1003 { 1004 case (array_key_exists('midcom_helper_datamanager2_save', $_REQUEST)): 1005 return 'save'; 1006 1007 case (array_key_exists('midcom_helper_datamanager2_next', $_REQUEST)): 1008 return 'next'; 1009 1010 case (array_key_exists('midcom_helper_datamanager2_previous', $_REQUEST)): 1011 return 'previous'; 1012 1013 case (array_key_exists('midcom_helper_datamanager2_cancel', $_REQUEST)): 1014 return 'cancel'; 1015 1016 case (array_key_exists('midcom_helper_datamanager2_preview', $_REQUEST)): 1017 return 'preview'; 1018 1019 default: 1020 return 'edit'; 1021 } 1022 } 1028 1023 } 1024 ?> trunk/midcom/midcom.helper.datamanager2/locale/default.en.txt
r15960 r16485 16 16 ---STRINGEND 17 17 18 ---STRING add new file 19 Add a new file 20 ---STRINGEND 21 18 22 ---STRING archived image 19 23 Archived image … … 53 57 ---STRINGEND 54 58 59 ---STRING drag and drop to sort 60 Drag and drop to sort 61 ---STRINGEND 62 55 63 ---STRING field %s is required 56 64 The field %s is required, please fill it out. … … 73 81 ---STRINGEND 74 82 83 ---STRING lock will expire on %s 84 Lock will expire on %s 85 ---STRINGEND 86 75 87 ---STRING midcom.helper.datamanager2 76 88 Data management and form rendering library … … 81 93 ---STRINGEND 82 94 95 ---STRING object locked 96 Object locked 97 ---STRINGEND 98 83 99 ---STRING passwords do not match 84 100 The passwords do not match. … … 101 117 ---STRINGEND 102 118 119 ---STRING this object was locked by %s 120 This object was locked by %s 121 ---STRINGEND 122 103 123 ---STRING type blobs: file size 104 124 File size … … 117 137 ---STRINGEND 118 138 139 ---STRING type number: value must not be larger then %s 140 The value of this field may not be larger then %s. 141 ---STRINGEND 142 143 ---STRING type number: value must not be smaller then %s 144 The value of this field may not be smaller then %s. 145 ---STRINGEND 146 119 147 ---STRING type php: parse error in line %s 120 148 Parse Error in line %s 121 149 ---STRINGEND 122 150 123 ---STRING type number: value must not be larger then %s124 The value of this field may not be larger then %s.125 ---STRINGEND126 127 ---STRING type number: value must not be smaller then %s128 The value of this field may not be smaller then %s.129 ---STRINGEND130 131 151 ---STRING type select: multiselect not allowed 132 152 No multiple selection allowed for this field. … … 153 173 ---STRINGEND 154 174 155 ---STRING add new file156 Add a new file157 ---STRINGEND158 159 175 ---STRING upload image 160 176 Upload image … … 221 237 ---STRINGEND 222 238 223 ---STRING drag and drop to sort224 Drag and drop to sort 225 ---STRINGEND 226 239 ---STRING break the lock 240 Break the lock 241 ---STRINGEND 242 trunk/midcom/midcom.helper.datamanager2/locale/default.fi.txt
r14715 r16485 16 16 ---STRINGEND 17 17 18 ---STRING add new file 19 20 ---STRINGEND 21 18 22 ---STRING archived image 19 23 Arkistoitu kuva … … 52 56 ---STRINGEND 53 57 58 ---STRING drag and drop to sort 59 JÀrjestele hiirellÀ raahaamalla 60 ---STRINGEND 61 54 62 ---STRING field %s is required 55 63 KenttÀ %s on pakollinen, ole hyvÀ ja tÀytÀ se. … … 72 80 ---STRINGEND 73 81 82 ---STRING lock will expire on %s 83 Lukko avautuu ajalla %s 84 ---STRINGEND 85 74 86 ---STRING midcom.helper.datamanager2 75 87 Tiedonhallinta- ja lomakekirjasto … … 80 92 ---STRINGEND 81 93 94 ---STRING object locked 95 Kohde lukittu 96 ---STRINGEND 97 82 98 ---STRING passwords do not match 83 99 Salasanat eivÀt tÀsmÀÀ … … 100 116 ---STRINGEND 101 117 118 ---STRING this object was locked by %s 119 TÀmÀn kohteen lukitsi %s 120 ---STRINGEND 121 102 122 ---STRING type blobs: file size 103 123 Tiedoston koko … … 124 144 ---STRINGEND 125 145 146 ---STRING type php: parse error in line %s 147 148 ---STRINGEND 149 126 150 ---STRING type select: multiselect not allowed 127 151 Monivalinta ei ole sallittu … … 156 180 ---STRINGEND 157 181 182 ---STRING validation failed: date 183 184 ---STRINGEND 185 158 186 ---STRING validation failed: email 159 187 TÀmÀ ei ole oikea sÀhköpostiosoite … … 208 236 ---STRINGEND 209 237 210 ---STRING drag and drop to sort211 JÀrjestele hiirellÀ raahaamalla 212 ---STRINGEND 213 238 ---STRING break the lock 239 Murra lukko 240 ---STRINGEND 241
