CMS  Version 3.9
image_picker.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 Fakoli::using("image");
35 
36 $mode = $_GET["Mode"]; // "insert" or "select" - "select" is default
37 $editor = $_GET["Editor"]; // in "insert" mode - ID of the RTE to insert the image into
38 $field = $_GET["Field"]; // in "select" mode - ID of the field to set the value of
39 $preview = $_GET["Preview"]; // in "select" mode - ID of the element to display the preview thumbnail.
40 $gallery_id = checkNumeric($_GET["gallery_id"]);
41 
42 $title = ($mode == "insert") ? "Insert Images" : "Select an Image";
43 
44 $galleries = Query::create(ImageGallery, "WHERE hidden=0 ORDER BY gallery_name")->execute();
45 
46 if (!$gallery_id && count($galleries) > 0)
47 {
48  $gallery_id = $galleries[0]->gallery_id;
49 }
50 
51 $script .= <<<ENDSCRIPT
52 <script type="text/javascript">
53 window.addEvent('domready', function()
54 {
55  new ImagePicker().setMode('$mode', '$field', '$preview');
56 });
57 </script>
58 ENDSCRIPT;
59 
61 if ($gallery_id)
62 {
63  $gallery->load($gallery_id);
64  $images = $gallery->Images();
65 }
66 else
67 {
68  $images = array();
69 }
70 
71 $view = new ImageListView($images, "javascript:new ImagePicker().selectImage({image_id}, '{title:jsSafe}')");
72 
73 ?>
74 <div class='image_picker_header'>
75 <div style="float: left; width: auto"><strong>Gallery </strong>
76  <select name="gallery_id" id="gallery_id" onchange="new ImagePicker().showImages(this.value)">
77 <?
78  foreach($galleries as $gallery)
79  {
80  option($gallery->gallery_id, $gallery->gallery_name, $gallery_id);
81  }
82 ?>
83  </select>
84 </div>
85 <div style="float: right;width: auto"><button class="button" onclick="new ImagePicker().uploadImage()"<?if (!$gallery_id) echo " disabled='disabled'"?>>Upload Image...</button></div>
86 <div style="clear:both"></div>
87 </div>
88 <div id="image_list" style="overflow:auto; width:95%; height: 300px;border: solid 1px #666; margin-left: 10px; padding: 2px; background-color: #fff">
89 <?
90 $view->drawGrid();
91 ?>
92 </div>
93 <table border="0" style="width: 100%" class="layout">
94  <tr>
95  <td style="width: 50%"><div style="display: block; float: right; margin: 10px"><div id="image_picker_preview"></div></div></td>
96  <td style="width: 50%">
97  <table class="layout">
98 
99 <?
100 if ($mode != "select")
101 {
102 ?>
103  <tr>
104  <td><label for="alignment">Alignment:</label></td>
105  <td>
106  <select id="alignment" name="alignment" style="width: 120px">
107  <option value="">Inline with Text</option>
108  <option value="left">Left</option>
109  <option value="center">Center</option>
110  <option value="right">Right</option>
111  </select>
112  </td>
113  </tr>
114  <tr>
115  <td><label for="width">Width:</label></td>
116  <td><input type="text" style="width: 60px" id="width" name="width" value="" onkeypress="return new ImagePicker().maskInput(event)" onkeyup="new ImagePicker().changeWidth()"/> pixels</td>
117  </tr>
118  <tr>
119  <td><label for="height">Height:</label></td>
120  <td><input type="text" style="width: 60px" id="height" name="height" value="" onkeypress="return new ImagePicker().maskInput(event)" onkeyup="new ImagePicker().changeHeight()"/> pixels</td>
121  </tr>
122  <tr>
123  <td colspan="2"><input type="checkbox" id="aspect" name="aspect" value="1" checked />&nbsp;<label for="aspect">Maintain aspect ratio</label></td>
124  </tr>
125 
126  <tr>
127  <td colspan="2" style="text-align: center"><br/>
128  <input type="button" class="button" name="insert" value="Insert Image" onclick="new ImagePicker().insertImage()"/>
129  </td>
130  </tr>
131 <?
132 }
133 else
134 {
135 ?>
136  <tr>
137  <td style="text-align: center"><br/>
138  <input type="button" class="button" name="insert" value="Select Image" onclick="new ImagePicker().setSelectedImage('<?php echo $field ?>')"/>
139  </td>
140  <td style="text-align: center"><br/>
141  <input type="button" class="button" name="insert" value="Clear Image" onclick="new ImagePicker().clearImage('<?php echo $field ?>')"/>
142  </td>
143  </tr>
144 <?
145 }
146 ?>
147  </table>
148  </td>
149  </tr>
150 </table>
& nbsp
Definition: index.inc:49
$helpTree style
Definition: tree.inc:46
$images
Definition: images.inc:46
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
$topicList colspan
Definition: group_form.inc:54
if(! $gallery_id &&count($galleries) > 0) $script
$preview
$galleries
$gallery_id
$mode
$field
$view
$gallery
$title
$editor