Пример #1
0
		<select name="location" size="10">
		<option value='' selected></option>
		<?php 
$locations = Model_Kwalbum_Location::getNameArray($user);
foreach ($locations as $name) {
    echo "<option value='{$name}'>{$name}</option>";
}
?>
		</select>
	</td>
	<td>
		Tags:<br/>
		<select name="tags" multiple size="10">
		<option value='' selected></option>
		<?php 
$tags = Model_Kwalbum_Tag::getNameArray();
foreach ($tags as $name) {
    echo "<option value='{$name}'>{$name}</option>";
}
?>
		</select>
	</td>
	<td>
		People:<br/>
		<select name="people" multiple size="10">
		<option value='' selected></option>
		<?php 
$people = Model_Kwalbum_Person::getNameArray();
if (!$user->can_see_all) {
    $persons = array();
    foreach ($people as $name) {
Пример #2
0
<div class="box">
	<big><b><?php 
echo html::anchor($kwalbum_url . '/~admin', 'Admin Options');
?>
: Editing Tags</b></big>

<table border="1">
	<tr><th>Count</th><th style="width:255px;">Name</th><th>Delete?</th></tr>
<?php 
$tags = Model_Kwalbum_Tag::getAllArray();
foreach ($tags as $tag) {
    echo "\t<tr id='row{$tag['id']}'><td>" . html::anchor($kwalbum_url . '/tags/' . $tag['name'], $tag['count']) . "</td><td><span id='tag{$tag['id']}'>{$tag['name']}</span></td><td style='text-align:center'>" . "<a href='#' onClick='deleteTag({$tag['id']});return false;'>[X]</a></td></tr>";
}
echo "</table></div>";
echo html::script($kwalbum_url . '/media/ajax/jquery.jeditable.mini.js');
?>
<script type="text/javascript">
function deleteTag(id){
	if (confirm('You are about to permanently delete "'+$('#tag'+id).text()+'"')){
			$.post("<?php 
echo $kwalbum_url;
?>
/~ajaxAdmin/DeleteTag", {id:id},function(){$('#row'+id).hide();});
			$('#tag'+id).text('deleting...');
	}
}
<?php 
foreach ($tags as $tag) {
    ?>
	$('#tag<?php 
    echo $tag['id'];
Пример #3
0
 /**
  * Save object changes to the database through inserts or updates
  *
  * @param boolean $update_update_date_with_update_date
  * @return Model_Kwalbum_Item
  */
 public function save($update_update_date_with_update_date = true)
 {
     // Set type
     $types = array_flip(Model_Kwalbum_Item::$types);
     $type_id = $types[$this->type];
     // Set location
     // Item has an original location so check for name changes
     if ($this->_location_id) {
         if (trim($this->location) != $this->_original_location) {
             // Update original location's item count if the name is different
             DB::query(Database::UPDATE, "\n\t\t\t\t\tUPDATE kwalbum_locations loc\n\t\t\t\t\tLEFT JOIN kwalbum_locations p ON (p.id = loc.parent_location_id)\n\t\t\t\t\tSET loc.count = loc.count-1, p.child_count = p.child_count-1\n\t\t\t\t\tWHERE loc.id = :id")->param(':id', $this->_location_id)->execute();
         } else {
             // Use the original id if there are no changes
             $location_id = $this->_location_id;
         }
     }
     // If there is no location id set then there is a change so get id for new location name
     if (!isset($location_id)) {
         $names = explode(trim(self::get_config('location_separator_1')), $this->location);
         foreach ($names as $i => $name) {
             $name = trim($name);
             if (!$name) {
                 unset($names[$i]);
             }
         }
         $this->location = implode(trim(self::get_config('location_separator_1')), $names);
         if (empty($this->location)) {
             // The location name is unknown so use default unknown id and name
             $location_id = $this->_location_id = 1;
             $result = DB::query(Database::SELECT, "\n\t\t\t\t\tSELECT name\n\t\t\t\t\tFROM kwalbum_locations\n\t\t\t\t\tWHERE id = 1\n\t\t\t\t\tLIMIT 1")->execute();
             $this->location = $this->_original_location = $result[0]['name'];
         } else {
             // Get new location id for known name
             $loc_name = $this->location;
             $names = explode(trim(self::get_config('location_separator_1')), $loc_name);
             if (count($names) > 1) {
                 $parent_loc_name = trim($names[0]);
                 array_shift($names);
                 foreach ($names as $i => $name) {
                     $names[$i] = trim($name);
                     if (!$name) {
                         unset($names[$i]);
                     }
                 }
                 $loc_name = implode(self::get_config('location_separator_2'), $names);
                 if (!$loc_name) {
                     $loc_name = $parent_loc_name;
                     unset($parent_loc_name);
                 }
             }
             // Get id if new location already exists
             if (isset($parent_loc_name)) {
                 $result = DB::query(Database::SELECT, "\n\t\t\t\t\t\tSELECT loc.id\n\t\t\t\t\t\tFROM kwalbum_locations loc\n\t\t\t\t\t\tLEFT JOIN kwalbum_locations p ON (p.id = loc.parent_location_id)\n\t\t\t\t\t\tWHERE loc.name = :name AND p.name = :parent_name\n\t\t\t\t\t\tLIMIT 1")->param(':name', $loc_name)->param(':parent_name', $parent_loc_name)->execute();
             } else {
                 $result = DB::query(Database::SELECT, "\n\t\t\t\t\t\tSELECT id\n\t\t\t\t\t\tFROM kwalbum_locations\n\t\t\t\t\t\tWHERE name = :name\n\t\t\t\t\t\tLIMIT 1")->param(':name', $loc_name)->execute();
             }
             // If new location does not exist then create it
             if ($result->count() == 0) {
                 if (isset($parent_loc_name)) {
                     // Get parent location id
                     $result = DB::query(Database::SELECT, "\n\t\t\t\t\t\t\tSELECT id\n\t\t\t\t\t\t\tFROM kwalbum_locations\n\t\t\t\t\t\t\tWHERE name = :name\n\t\t\t\t\t\t\tLIMIT 1")->param(':name', $parent_loc_name)->execute();
                     // If new location's parent does not exist then create it
                     if ($result->count() == 0) {
                         $result = DB::query(Database::INSERT, "\n\t\t\t\t\t\t\t\t\tINSERT INTO kwalbum_locations\n\t\t\t\t\t\t\t\t\t(name)\n\t\t\t\t\t\t\t\t\tVALUES (:name)")->param(':name', $parent_loc_name)->execute();
                     }
                     $parent_loc_id = $result[0];
                     // Create new location with parent
                     $result = DB::query(Database::INSERT, "\n\t\t\t\t\t\t\tINSERT INTO kwalbum_locations\n\t\t\t\t\t\t\t(name, parent_location_id)\n\t\t\t\t\t\t\tVALUES (:name, :parent_id)")->param(':name', $loc_name)->param(':parent_id', $parent_loc_id)->execute();
                 } else {
                     // Create new location without parent
                     $result = DB::query(Database::INSERT, "\n\t\t\t\t\t\t\tINSERT INTO kwalbum_locations\n\t\t\t\t\t\t\t(name)\n\t\t\t\t\t\t\tVALUES (:name)")->param(':name', $loc_name)->execute();
                 }
                 $location_id = $result[0];
             } else {
                 $location_id = $result[0]['id'];
             }
         }
         // Update count on new location
         DB::query(Database::UPDATE, "UPDATE kwalbum_locations loc LEFT JOIN kwalbum_locations p ON (p.id = loc.parent_location_id)\n\t\t\t\tSET loc.count = loc.count+1, p.child_count = p.child_count+1\n\t\t\t\tWHERE loc.id = :id")->param(':id', $location_id)->execute();
     }
     // Save any changes to location id and original name
     $this->_location_id = $location_id;
     $this->_original_location_name = $this->location;
     // Set update_date
     if ($update_update_date_with_update_date) {
         $this->update_date = date('Y-m-d H:i:s');
     }
     // Save actual item
     if ($this->loaded == false) {
         // create_date is never updated, only set at insert
         $this->create_date = $this->update_date;
         $query = DB::query(Database::INSERT, "INSERT INTO kwalbum_items\n\t\t\t\t(type_id, location_id, user_id, description, path, filename,\n\t\t\t\t\tcreate_dt, update_dt, visible_dt, sort_dt,\n\t\t\t\t\tcount, latitude, longitude, hide_level)\n\t\t\t\tVALUES (:type_id, :location_id, :user_id, :description, :path, :filename,\n\t\t\t\t\t:create_date, :update_date, :visible_date, :sort_date,\n\t\t\t\t\t:count, :latitude, :longitude, :hide_level)")->param(':create_date', $this->create_date);
         if (!$this->visible_date) {
             $this->visible_date = $this->update_date;
         }
         if (!$this->sort_date) {
             $this->sort_date = $this->update_date;
         }
     } else {
         $query = DB::query(Database::UPDATE, "UPDATE kwalbum_items\n\t\t\t\tSET type_id = :type_id, location_id = :location_id, user_id = :user_id,\n\t\t\t\t\tdescription = :description, path = :path, filename = :filename,\n\t\t\t\t\tupdate_dt = :update_date, sort_dt = :sort_date, visible_dt = :visible_date,\n\t\t\t\t\tcount = :count, latitude = :latitude, longitude = :longitude,\n\t\t\t\t\thide_level = :hide_level\n\t\t\t\tWHERE id = :id")->param(':id', $this->id);
     }
     $query->param(':type_id', $type_id)->param(':location_id', $location_id)->param(':user_id', $this->user_id)->param(':description', trim($this->description))->param(':path', str_replace(self::get_config('item_path'), '', $this->path))->param(':filename', trim($this->filename))->param(':update_date', $this->update_date)->param(':visible_date', $this->visible_date)->param(':sort_date', $this->sort_date)->param(':count', (int) $this->count)->param(':latitude', $this->latitude ? $this->latitude : 0)->param(':longitude', $this->longitude ? $this->longitude : 0)->param(':hide_level', $this->hide_level);
     $result = $query->execute();
     if (!$this->loaded) {
         $this->id = $result[0];
         $this->loaded = true;
     }
     // Set tags and persons once we know we have an item_id for the relationship.
     // Remove duplicates of new persons and tags while making sure
     // the arrays exist before recreating the relationhips
     $this->_persons = $this->getPersons();
     $this->_tags = $this->getTags();
     // Remove old item-person and item-tag relations
     $this->_delete_person_relations();
     $this->_delete_tag_relations();
     // Create new item-person and item-tag relations
     $person = new Model_Kwalbum_Person();
     foreach ($this->_persons as $name) {
         $name = trim($name);
         if ($name != '') {
             $person->clear();
             $person->name = $name;
             $person->save();
             DB::query(Database::INSERT, "INSERT INTO kwalbum_items_persons\n\t\t\t\t\t(item_id, person_id)\n\t\t\t\t\tVALUES (:item_id, :person_id)")->param(':item_id', $this->id)->param(':person_id', $person->id)->execute();
             $person->count = $person->count + 1;
             $person->save();
         }
     }
     $tag = new Model_Kwalbum_Tag();
     foreach ($this->_tags as $name) {
         $name = trim($name);
         if ($name != '') {
             $tag->clear();
             $tag->name = $name;
             $tag->save();
             DB::query(Database::INSERT, "INSERT INTO kwalbum_items_tags\n\t\t\t\t\t(item_id, tag_id)\n\t\t\t\t\tVALUES (:item_id, :tag_id)")->param(':item_id', $this->id)->param(':tag_id', $tag->id)->execute();
             $tag->count = $tag->count + 1;
             $tag->save();
         }
     }
     return $this;
 }