/[drupal]/contributions/modules/imagepicker/imagepicker.edit.inc
ViewVC logotype

Contents of /contributions/modules/imagepicker/imagepicker.edit.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Thu Aug 28 21:25:20 2008 UTC (15 months ago) by hutch
Branch: MAIN
CVS Tags: DRUPAL-6--1-4, DRUPAL-6--1-5, DRUPAL-6--1-0, DRUPAL-6--1-1, DRUPAL-6--1-2, DRUPAL-6--1-3, HEAD
Branch point for: DRUPAL-6--2
Changes since 1.2: +9 -4 lines
File MIME type: text/x-php
improved menus, added admin mode to image browser, added drupal paging to image browser, added groups
1 <?php
2 // $Id: imagepicker.edit.inc,v 1.2 2008/07/01 15:02:55 hutch Exp $
3 // $Name: HEAD $
4
5 /**
6 * @file
7 * Contains the functions pertaining to editing image information
8 */
9
10 /**
11 * Menu callback; fetches the image edit form for imagepicker
12 */
13 // iframe
14 function imagepicker_image_edit($img_id) {
15 $content = _imagepicker_edit_img($img_id, FALSE);
16 theme('imagepicker', $content);
17 }
18
19 // account
20 function imagepicker_user_image_edit($img_id) {
21 $content = _imagepicker_edit_img($img_id, TRUE);
22 return $content;
23 }
24
25 function imagepicker_edit_form(&$form_state, $img, $account=FALSE) {
26 $form['title'] = array(
27 '#type' => 'textfield',
28 '#title' => t('Title'),
29 '#description' => t('Edit title of your image'),
30 '#default_value' => htmlspecialchars_decode($img['img_title']),
31 '#prefix' => '<div id="imgp_edit_form">'
32 );
33 $form['description'] = array(
34 '#type' => 'textarea',
35 '#title' => t('Description'),
36 '#rows' => 2,
37 '#cols' => 80,
38 '#description' => t('Edit description of your image'),
39 '#default_value' => htmlspecialchars_decode($img['img_description']),
40 '#suffix' => '</div>'
41 );
42 if ($account) {
43 $form['account'] = array(
44 '#type' => 'hidden',
45 '#value' => 1,
46 );
47 }
48 $form['img_id'] = array(
49 '#type' => 'hidden',
50 '#value' => $img['img_id'],
51 );
52 $form['submit'] = array(
53 '#type' => 'submit',
54 '#value' => t('Submit'),
55 '#prefix' => '<div id="imgp_controls">',
56 '#submit' => array('imagepicker_edit_form_process'),
57 );
58 $form['cancel'] = array(
59 '#type' => 'submit',
60 '#value' => t('Cancel'),
61 '#suffix' => '</div>',
62 '#submit' => array('imagepicker_edit_form_cancel'),
63 );
64 return $form;
65 }
66
67 /**
68 * Submit form functions
69 */
70 function imagepicker_edit_form_cancel($form, &$form_state) {
71 global $user;
72 if ($form_state['values']['account']) {
73 $outpath = 'user/'. $user->uid .'/imagepicker/images/browse';
74 }
75 else {
76 $outpath = 'imagepicker/browse/'. $img_id;
77 }
78 drupal_set_message(t('Cancelled.'));
79 drupal_goto($outpath);
80 }
81
82
83 function imagepicker_edit_form_process($form, &$form_state) {
84 global $user;
85 $img_id = $form_state['values']['img_id'];
86 if ($form_state['values']['account']) {
87 $outpath = 'user/'. $user->uid .'/imagepicker/images/browse';
88 }
89 else {
90 $outpath = 'imagepicker/browse/'. $img_id;
91 }
92 $result = db_query_range("SELECT uid, img_name FROM {imagepicker} WHERE img_id = '%d'", $img_id, 0, 1);
93 $img = db_fetch_array($result);
94 if ($img) {
95 if ($img['uid'] == $user->uid) {
96 $title = htmlspecialchars($form_state['values']['title']);
97 $description = htmlspecialchars($form_state['values']['description']);
98 $date = date('Y-m-d H:i:s');
99 if (db_query("UPDATE {imagepicker} SET img_title = '%s', img_description = '%s', img_date = '%s' WHERE img_id = '%d'",
100 array($title, $description, $date, $img_id))) {
101 drupal_set_message(t('Image was successfully updated.'));
102 drupal_goto($outpath);
103 }
104 else {
105 drupal_set_message(t('Error while updating image.'));
106 }
107 }
108 else {
109 drupal_set_message(t('This image does not belong to you.'), 'error');
110 watchdog('imagepicker', 'User uid %d attempted to edit image belonging to user uid %d', array($user->uid, $img['uid']), WATCHDOG_WARNING);
111 }
112 }
113 else {
114 drupal_set_message(t('Image not found.'), 'error');
115 }
116
117 drupal_goto($outpath);
118 }
119
120 /**
121 * private functions
122 */
123 function _imagepicker_edit_img($img_id, $account=FALSE) {
124 $content = '';
125 $img = _imagepicker_get_img($img_id);
126 if ($img) {
127 $imgsrc = imagepicker_get_image_path($img, 'browser');
128 $content .= "<div class='imgp_help'>". t('Edit image details') ."</div>";
129 $content .= '<div id="imgp_img_holder"><img src="'. $imgsrc .'" alt="'. check_plain($img['img_title']) .'" /></div>';
130 $content .= drupal_get_form('imagepicker_edit_form', $img, $account);
131 }
132 else {
133 drupal_set_message(t('Image not found in edit.'), 'error');
134 $content = '';
135 }
136
137 return $content;
138 }
139

  ViewVC Help
Powered by ViewVC 1.1.2