Modified settings table. Added samble labels.
[irreco.git] / database / php / irreco_webdb_server.php
blob0a0516c7eae1bdec7e6aa6bd3423c9eab0435616
1 <?php
3 /*
4 * irreco - Ir Remote Control
5 * Copyright (C) 2007,2008 Arto Karppinen (arto.karppinen@iki.fi),
6 * Joni Kokko (t5kojo01@students.oamk.fi),
7 * Sami Mäki (kasmra@xob.kapsi.fi),
8 * Harri Vattulainen (t5vaha01@students.oamk.fi)
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 require_once 'irreco_webdb_log.php';
26 require_once 'XML/RPC2/Server.php';
28 class IrrecoWebdbServer
31 const ADD_USER_ERROR_MSG = "Adding user failed.";
32 const UPLOAD_CONFIGURATION_ERROR_MSG = "Uploading configuration\nfailed.";
33 const USERNAME_AND_PASSWORD_MISMATCH_MSG = "Username and password mismatch.";
34 const FILE_ALREADY_EXIST_MSG = "Database already contains identical device.";
35 const HASH_AND_DATA_MISMATCH_MSG = "File hash and file data don't match.";
36 const FAULTCODE_ERROR_MSG = "\nInvalid string faultCode.";
37 const LOGIN_ERROR_MSG = "Login failed.";
38 const EMPTY_DB_MSG = "Database is empty.";
40 const ADD_USER_ERROR = 10001;
41 const UPLOAD_CONFIGURATION_ERROR = 10002;
42 const USERNAME_AND_PASSWORD_MISMATCH = 10003;
43 const FILE_ALREADY_EXIST = 10004;
44 const HASH_AND_DATA_MISMATCH = 10005;
45 const FAULTCODE_ERROR = 10006;
46 const LOGIN_ERROR = 10007;
47 const EMPTY_DB_ERROR = 10008;
49 private $database;
51 public function __construct($database)
53 $this->database = $database;
56 /**
57 * Sum two numbers.
59 * @param int num_a
60 * @param int num_b
61 * @return int Sum of integers
63 public function sum($num_a, $num_b)
65 IrrecoLog::$server->log('XML-RPC sum');
66 return $num_a + $num_b;
69 /**
70 * Add user to database
72 * Returns TRUE if user is added successfully to database.
74 * @param string name Username
75 * @param string email full email address
76 * @param string passwd sha1-hash of password
77 * @return boolean User added successfully
79 function addUser($name, $email, $passwd)
81 IrrecoLog::$server->log('XML-RPC addUser');
82 $table = 'user';
84 /* Check for faultCode */
85 if(strstr($name, "faultCode")) {
86 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
87 self::FAULTCODE_ERROR);
89 if(strstr($email, "faultCode")) {
90 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
91 self::FAULTCODE_ERROR);
94 /* Check parameters here */
95 if(strlen($name) < 6) {
96 throw new XML_RPC2_FaultException(self::ADD_USER_ERROR_MSG,
97 self::ADD_USER_ERROR);
100 if(strlen($email) < 6) {
101 throw new XML_RPC2_FaultException(self::ADD_USER_ERROR_MSG,
102 self::ADD_USER_ERROR);
105 if(strlen($passwd) < 6) {
106 throw new XML_RPC2_FaultException(self::ADD_USER_ERROR_MSG,
107 self::ADD_USER_ERROR);
110 if(!strstr($email, "@")) {
111 throw new XML_RPC2_FaultException(self::ADD_USER_ERROR_MSG,
112 self::ADD_USER_ERROR);
115 if(!strstr($email, ".")) {
116 throw new XML_RPC2_FaultException(self::ADD_USER_ERROR_MSG,
117 self::ADD_USER_ERROR);
120 $data = $this->database->addUser($name, $email, $passwd, $table);
122 if ($data == FALSE) {
123 /* if failed */
124 throw new XML_RPC2_FaultException(self::ADD_USER_ERROR_MSG,
125 self::ADD_USER_ERROR);
127 return $data;
131 * Add configuration to database
133 * Returns error message or 'configuration added successfully' as string
136 * @param string backend Name for Backend. e.g. "IRTrans Transceiver"
137 * @param string category Name for Category. e.g. "Tv"
138 * @param string manufacturer Name for Manufacturer. e.g. "Sony"
139 * @param string model Name for Model. e.g. "Sony"
140 * @param string user Username
141 * @param string password sha1-hash of password
142 * @param string file_hash sha1-hash of file_data
143 * @param string file_name Name for File
144 * @param string file_data Content of file
145 * @return string
147 function uploadConfiguration($backend,
148 $category,
149 $manufacturer,
150 $model,
151 $user,
152 $password,
153 $file_hash,
154 $file_name,
155 $file_data)
157 IrrecoLog::$server->log('XML-RPC uploadConfiguration');
159 /* Check for faultCode */
160 if(strstr($backend, "faultCode")) {
161 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
162 self::FAULTCODE_ERROR);
164 if(strstr($category, "faultCode")) {
165 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
166 self::FAULTCODE_ERROR);
168 if(strstr($manufacturer, "faultCode")) {
169 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
170 self::FAULTCODE_ERROR);
172 if(strstr($model, "faultCode")) {
173 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
174 self::FAULTCODE_ERROR);
176 if(strstr($user, "faultCode")) {
177 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
178 self::FAULTCODE_ERROR);
180 if(strstr($file_hash, "faultCode")) {
181 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
182 self::FAULTCODE_ERROR);
184 if(strstr($file_name, "faultCode")) {
185 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
186 self::FAULTCODE_ERROR);
188 if(strstr($file_data, "faultCode")) {
189 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
190 self::FAULTCODE_ERROR);
193 /* Check parameters here */
194 if(strlen($backend) == 0) {
195 throw new XML_RPC2_FaultException(
196 self::UPLOAD_CONFIGURATION_ERROR_MSG,
197 self::UPLOAD_CONFIGURATION_ERROR);
200 if(strlen($category) == 0) {
201 throw new XML_RPC2_FaultException(
202 self::UPLOAD_CONFIGURATION_ERROR_MSG,
203 self::UPLOAD_CONFIGURATION_ERROR);
206 if(strlen($manufacturer) == 0) {
207 throw new XML_RPC2_FaultException(
208 self::UPLOAD_CONFIGURATION_ERROR_MSG,
209 self::UPLOAD_CONFIGURATION_ERROR);
212 if(strlen($model) == 0) {
213 throw new XML_RPC2_FaultException(
214 self::UPLOAD_CONFIGURATION_ERROR_MSG,
215 self::UPLOAD_CONFIGURATION_ERROR);
218 if(strlen($user) < 6) {
219 throw new XML_RPC2_FaultException(
220 self::UPLOAD_CONFIGURATION_ERROR_MSG,
221 self::UPLOAD_CONFIGURATION_ERROR);
224 if(strlen($password) < 6) {
225 throw new XML_RPC2_FaultException(
226 self::UPLOAD_CONFIGURATION_ERROR_MSG,
227 self::UPLOAD_CONFIGURATION_ERROR);
230 if(strlen($file_hash) != 40) {
231 throw new XML_RPC2_FaultException(
232 self::UPLOAD_CONFIGURATION_ERROR_MSG,
233 self::UPLOAD_CONFIGURATION_ERROR);
236 /* try to add data to db */
237 $table = 'configuration';
238 $return = $this->database->uploadConfiguration($backend,
239 $category,
240 $manufacturer,
241 $model,
242 $user,
243 $password,
244 $file_hash,
245 $file_name,
246 $file_data);
248 if ($return == 'username and password mismatch.') {
249 throw new XML_RPC2_FaultException(
250 self::USERNAME_AND_PASSWORD_MISMATCH_MSG,
251 self::USERNAME_AND_PASSWORD_MISMATCH);
253 else if ($return == 'file already exist.') {
254 throw new XML_RPC2_FaultException(
255 self::FILE_ALREADY_EXIST_MSG,
256 self::FILE_ALREADY_EXIST);
258 else if ($return == 'file hash and file data mismatch.') {
259 throw new XML_RPC2_FaultException(
260 self::HASH_AND_DATA_MISMATCH_MSG,
261 self::HASH_AND_DATA_MISMATCH);
264 return $return;
268 * Get list of categories that have configurations in them.
270 * @return array
272 function getCategories()
274 IrrecoLog::$server->log('XML-RPC getCategories');
275 $data = $this->database->getCategoryList();
277 $array = array();
278 foreach ($data as $item) {
279 array_push($array, $item->name);
282 IrrecoLog::$database->log("Category list:\n" .
283 IrrecoLog::getVarDump($array));
284 return $array;
287 * Get list of all categories. Even those that don't have
288 * configurations in them.
290 * @return array
292 function getAllCategories()
294 IrrecoLog::$server->log('XML-RPC getAllCategories');
295 $data = $this->database->getWholeCategoryList();
297 $array = array();
298 foreach ($data as $item) {
299 array_push($array, $item->name);
302 IrrecoLog::$database->log("Category list:\n" .
303 IrrecoLog::getVarDump($array));
304 return $array;
308 * Get list of manufacturers for category.
310 * @param string category Name for Category. e.g. "Tv"
311 * @return array
313 function getManufacturers($category)
315 IrrecoLog::$server->log('XML-RPC getManufacturers');
316 $data = $this->database->getManufacturerList($category);
318 $array = array();
319 foreach ($data as $item) {
320 array_push($array, $item->name);
323 IrrecoLog::$database->log("Manufacturer list:\n" .
324 IrrecoLog::getVarDump($array));
325 return $array;
329 * Get list of all manufacturers. Even those that don't have
330 * configurations in them.
332 * @return array
334 function getAllManufacturers()
336 IrrecoLog::$server->log('XML-RPC getAllManufacturers');
337 $data = $this->database->getWholeManufacturerList();
339 $array = array();
340 foreach ($data as $item) {
341 array_push($array, $item->name);
344 IrrecoLog::$database->log("Manufacturer list:\n" .
345 IrrecoLog::getVarDump($array));
346 return $array;
350 * Get list of models by manufacturer in selected category.
352 * @param string category Name for Category. e.g. "Tv"
353 * @param string manufacturer Name for Manufacturer. e.g. "Sony"
354 * @return array
356 function getModels($category,$manufacturer)
358 IrrecoLog::$server->log('XML-RPC getModels');
359 $data = $this->database->getModelList($category,$manufacturer);
361 $array = array();
362 foreach ($data as $item) {
363 array_push($array, $item->model);
366 IrrecoLog::$database->log("Model list:\n" .
367 IrrecoLog::getVarDump($array));
368 return $array;
373 * Get id list for configurations by model.
375 * This function is deprecated. Use the getConfigurations function
376 * instead.
377 * @param string model Name for Model. e.g. "xyz"
378 * @return array
380 function getConfigs($model)
382 IrrecoLog::$server->log('XML-RPC getConfigs');
383 $data = $this->database->getConfigs($model);
384 $array = array();
385 foreach ($data as $item) {
386 array_push($array, $item->id);
389 IrrecoLog::$database->log("Config id:\n" .
390 IrrecoLog::getVarDump($array));
391 return $array;
395 * Get id list for configurations by model and manufacturer
397 * @param string manufacturer Name for Manufacturer. e.g. "Sony"
398 * @param string model Name for Model. e.g. "xyz"
399 * @return array
401 function getConfigurations($manufacturer, $model)
403 IrrecoLog::$server->log('XML-RPC getConfigurations');
404 $data = $this->database->getConfigurations($manufacturer, $model);
406 $array = array();
407 foreach ($data as $item) {
408 array_push($array, $item->id);
411 IrrecoLog::$database->log("Config id:\n" .
412 IrrecoLog::getVarDump($array));
413 return $array;
417 * Get all data from configuration
419 * Returns user, backend, category, manufacturer,
420 * model, file_hash, file_name, uploaded, download_count
422 * This function is deprecated. Use the getConfigurationById function
423 * instead.
424 * @param string id id-number for configuration.
425 * @return struct
427 function getConfiguration($id)
429 IrrecoLog::$server->log('XML-RPC getConfiguration');
430 $data = $this->database->getConfiguration($id);
431 $array = array();
433 $array['user'] = $data[0]->user;
434 $array['backend'] = $data[0]->backend;
435 $array['category'] = $data[0]->category;
436 $array['manufacturer'] = $data[0]->manufacturer;
437 $array['model'] = $data[0]->model;
438 $array['file_hash'] = $data[0]->file_hash;
439 $array['file_name'] = $data[0]->file_name;
440 $array['uploaded'] = $data[0]->uploaded;
441 $array['download_count'] = $data[0]->download_count;
443 IrrecoLog::$database->log("Configuration:\n" .
444 IrrecoLog::getVarDump($array));
445 return $array;
449 * Get all data from configuration
451 * Returns user, backend, category, manufacturer,
452 * model, file_hash, file_name, uploaded, download_count
453 * @param int id id-number for configuration.
454 * @return struct
456 function getConfigurationById($id)
458 IrrecoLog::$server->log('XML-RPC getConfigurationById');
459 $data = $this->database->getConfiguration($id);
460 $array = array();
462 $array['user'] = $data[0]->user;
463 $array['backend'] = $data[0]->backend;
464 $array['category'] = $data[0]->category;
465 $array['manufacturer'] = $data[0]->manufacturer;
466 $array['model'] = $data[0]->model;
467 $array['file_hash'] = $data[0]->file_hash;
468 $array['file_name'] = $data[0]->file_name;
469 $array['uploaded'] = $data[0]->uploaded;
470 $array['download_count'] = $data[0]->download_count;
472 IrrecoLog::$database->log("Configuration:\n" .
473 IrrecoLog::getVarDump($array));
474 return $array;
479 * Get File
482 * Returns content of file
483 * @param string hash sha1-hash of file_data
484 * @param string name Name for File
485 * @return struct
487 function getFile($hash,$name)
489 IrrecoLog::$server->log('XML-RPC getFile');
490 $data = $this->database->getFileData($hash,$name);
492 $array = array();
494 $array['data']= $data[0]->data;
496 IrrecoLog::$database->log("Data:\n" .
497 IrrecoLog::getVarDump($array));
498 return $array;
503 * Get whether user already exists
505 * Returns TRUE if given name is already in database.
506 * Used at irreco_webdb_register_dlg when adding new user.
508 * @param string name Username
509 * @return boolean User exists
511 function getUserExists($name)
513 IrrecoLog::$server->log('XML-RPC getUserExists');
514 $table = 'user';
515 $data = $this->database->getNameId($table, $name);
517 if ($data == "") {
518 return FALSE;
519 } else {
520 return TRUE;
525 * Create new Theme
527 * Returns theme_id
528 * @param string name Name of Theme
529 * @param string comment
530 * @param string preview_button name of preview button
531 * @param string folder name of themefolder
532 * @param string user Username
533 * @param string password sha1-hash of password
534 * @return int
536 function createNewTheme($name, $comment, $preview_button,
537 $folder, $user, $password)
539 IrrecoLog::$server->log('XML-RPC createNewTheme');
540 $theme_id = $this->database->createNewTheme($name, $comment,
541 $preview_button,
542 $folder, $user,
543 $password);
545 if ($theme_id == 'username and password mismatch.') {
546 throw new XML_RPC2_FaultException(
547 self::USERNAME_AND_PASSWORD_MISMATCH_MSG,
548 self::USERNAME_AND_PASSWORD_MISMATCH);
551 IrrecoLog::$database->log("Theme_id: " . $theme_id . "\n");
552 return $theme_id;
556 * Set Theme downloadable
558 * @param int id id-number for theme.
559 * @param bool downloadable
560 * @param string user Username
561 * @param string password sha1-hash of password
562 * @return bool
564 function setThemeDownloadable($id, $downloadable, $user, $password)
566 IrrecoLog::$server->log('XML-RPC ThemeSetDownloadable');
567 $success = $this->database->setThemeDownloadable($id,
568 $downloadable,
569 $user,
570 $password);
572 if ($success == 'username and password mismatch.') {
573 throw new XML_RPC2_FaultException(
574 self::USERNAME_AND_PASSWORD_MISMATCH_MSG,
575 self::USERNAME_AND_PASSWORD_MISMATCH);
577 return TRUE;
581 * Get id list for themes
583 * @return array
585 function getThemes()
587 IrrecoLog::$server->log('XML-RPC getThemes');
588 $data = $this->database->getThemeList();
590 if ($data == 'Database is empty.') {
591 throw new XML_RPC2_FaultException(self::EMPTY_DB_MSG,
592 self::EMPTY_DB_ERROR);
595 $array = array();
596 foreach ($data as $item) {
597 array_push($array, $item->id);
600 IrrecoLog::$database->log("Theme id:\n" .
601 IrrecoLog::getVarDump($array));
602 return $array;
606 * Get all data from theme
608 * Returns name, user, comment, preview_button, folder,
609 * uploaded, modified, downloaded, download_count
610 * @param int id id-number for theme.
611 * @return struct
614 function getThemeById($id)
616 IrrecoLog::$server->log('XML-RPC getThemeById');
617 $data = $this->database->getTheme($id);
618 $array = array();
620 $array['name'] = $data[0]->name;
621 $array['user'] = $data[0]->user;
622 $array['comment'] = $data[0]->comment;
623 $array['preview_button'] = $data[0]->preview_button;
624 $array['folder'] = $data[0]->folder;
625 $array['uploaded'] = $data[0]->uploaded;
626 $array['modified'] = $data[0]->modified;
627 $array['downloaded'] = $data[0]->downloaded;
628 $array['download_count'] = intval($data[0]->download_count);
630 IrrecoLog::$database->log("Theme:\n" .
631 IrrecoLog::getVarDump($array));
632 return $array;
636 * Get theme versions by name
638 * Returns id-list
639 * @param string name name for theme.
640 * @return array
643 function getThemeVersionsByName($name)
645 IrrecoLog::$server->log('XML-RPC getThemeVersionsByName');
646 $data = $this->database->getThemeVersionsByName($name);
648 $array = array();
649 foreach ($data as $item) {
650 array_push($array, $item->id);
653 IrrecoLog::$database->log("Theme versions:\n".
654 IrrecoLog::getVarDump($array));
655 return $array;
659 * Get date for theme by id
661 * @param int id id-number for theme.
662 * @return string
665 function getThemeDateById($id)
667 IrrecoLog::$server->log('XML-RPC getThemeById');
668 $data = $this->database->getTheme($id);
670 IrrecoLog::$database->log("Theme-date: ".$data[0]->uploaded);
671 return $data[0]->uploaded;
675 * Add button to Theme
677 * Returns button_id
678 * @param string name Name of button
679 * @param bool allow_text
680 * @param string text_format_up
681 * @param string text_format_down
682 * @param int text_padding
683 * @param float text_h_align
684 * @param float text_v_align
685 * @param string image_up_hash
686 * @param string image_up_name
687 * @param string image_up
688 * @param string image_down_hash
689 * @param string image_down_name
690 * @param string image_down
691 * @param string folder
692 * @param int theme_id
693 * @param string user Username
694 * @param string password sha1-hash of password
695 * @return int
697 function addButtonToTheme($name, $allow_text, $text_format_up,
698 $text_format_down, $text_padding,
699 $text_h_align, $text_v_align,
700 $image_up_hash, $image_up_name, $image_up,
701 $image_down_hash, $image_down_name, $image_down,
702 $folder, $theme_id, $user, $password)
705 IrrecoLog::$server->log('XML-RPC addButtonToTheme');
707 $button_id = $this->database->addButtonToTheme(
708 $name, $allow_text, $text_format_up,
709 $text_format_down, $text_padding,
710 $text_h_align, $text_v_align,
711 $image_up_hash, $image_up_name,
712 base64_decode($image_up), $image_down_hash,
713 $image_down_name, base64_decode($image_down),
714 $folder, $theme_id, $user, $password);
716 if ($button_id == 'username and password mismatch.') {
717 throw new XML_RPC2_FaultException(
718 self::USERNAME_AND_PASSWORD_MISMATCH_MSG,
719 self::USERNAME_AND_PASSWORD_MISMATCH);
721 else if ($button_id == 'file hash and file data mismatch.') {
722 throw new XML_RPC2_FaultException(
723 self::HASH_AND_DATA_MISMATCH_MSG,
724 self::HASH_AND_DATA_MISMATCH);
727 IrrecoLog::$database->log("Button_id: " . $button_id . "\n");
728 return $button_id;
732 * Get id list of buttons for theme
734 * @param int theme_id id of theme
735 * @return array
737 function getButtons($theme_id)
739 IrrecoLog::$server->log('XML-RPC getButtons');
740 $data = $this->database->getButtonList($theme_id);
742 $array = array();
743 foreach ($data as $item) {
744 array_push($array, intval($item->id));
747 if (count($array) == 0) {
748 array_push($array, 0);
751 IrrecoLog::$database->log("Button id:\n".
752 IrrecoLog::getVarDump($array));
753 return $array;
757 * Get all data from Button
759 * Returns name, allow_text, text_format_up, text_format_down,
760 * text_padding, image_up_hash, image_up_name, base64 encoded image_up,
761 * image_down_hash, image_down_name, base64 encoded image_down, folder
762 * @param int id id-number for button.
763 * @return struct
765 function getButtonById($id)
767 IrrecoLog::$server->log('XML-RPC getButtonById');
768 $array = $this->database->getButton($id);
770 IrrecoLog::$database->log("Button:\n".
771 IrrecoLog::getVarDump($array));
772 return $array;
776 * Get preview button
778 * Returns base64 encoded image-data string.
779 * @param int theme_id id for theme
780 * @return string
783 function getPreviewButton($theme_id)
785 IrrecoLog::$server->log('XML-RPC getPreviewButton');
786 $data = $this->database->getPreviewButton($theme_id);
787 return base64_encode($data);
791 * Add background to Theme
793 * Returns background_id
794 * @param string name Name of background
795 * @param string image_hash sha1-hash of image-data
796 * @param string image_name Name for image
797 * @param string image Content of image
798 * @param string folder name of button-folder
799 * @param int theme_id id of theme
800 * @param string user Username
801 * @param string password sha1-hash of password
802 * @return int
804 function addBgToTheme($name, $image_hash, $image_name, $image,
805 $folder, $theme_id, $user, $password)
807 IrrecoLog::$server->log('XML-RPC addBgToTheme');
808 $bg_id = $this->database->addBgToTheme($name, $image_hash,
809 $image_name,
810 base64_decode($image),
811 $folder, $theme_id,
812 $user, $password);
814 if ($bg_id == 'username and password mismatch.') {
815 throw new XML_RPC2_FaultException(
816 self::USERNAME_AND_PASSWORD_MISMATCH_MSG,
817 self::USERNAME_AND_PASSWORD_MISMATCH);
819 else if ($bg_id == 'file hash and file data mismatch.') {
820 throw new XML_RPC2_FaultException(
821 self::HASH_AND_DATA_MISMATCH_MSG,
822 self::HASH_AND_DATA_MISMATCH);
825 IrrecoLog::$database->log("Bg_id: " . $bg_id . "\n");
826 return $bg_id;
830 * Get id list of backgrounds for theme
832 * @param int theme_id id of theme
833 * @return array
835 function getBackgrounds($theme_id)
837 IrrecoLog::$server->log('XML-RPC getBackgrounds');
838 $data = $this->database->getBgList($theme_id);
840 $array = array();
841 foreach ($data as $item) {
842 array_push($array, intval($item->id));
845 if (count($array) == 0) {
846 array_push($array, 0);
849 IrrecoLog::$database->log("Bg id:\n" .
850 IrrecoLog::getVarDump($array));
851 return $array;
855 * Get all data from Background
857 * Returns name, image_hash, image_name,
858 * folder and base64 encoded image_data
859 * @param int id id-number for background.
860 * @return struct
862 function getBgById($id)
864 IrrecoLog::$server->log('XML-RPC getBgById');
865 $array = $this->database->getBg($id);
867 IrrecoLog::$database->log("Bg:\n" .
868 IrrecoLog::getVarDump($array));
869 return $array;
873 * Login to database
875 * Returns TRUE if login successful, FALSE otherwise.
877 * @param string user Username
878 * @param string password sha1-hash of password
879 * @return boolean
881 function loginToDB($user, $password)
883 IrrecoLog::$server->log('XML-RPC loginToDB');
885 /* Check for faultCode */
886 if(strstr($user, "faultCode")) {
887 throw new XML_RPC2_FaultException(self::FAULTCODE_ERROR_MSG,
888 self::FAULTCODE_ERROR);
891 /* Check parameters here */
892 if(strlen($user) < 6) {
893 throw new XML_RPC2_FaultException(
894 self::LOGIN_ERROR_MSG,
895 self::LOGIN_ERROR);
898 if(strlen($password) < 6) {
899 throw new XML_RPC2_FaultException(
900 self::LOGIN_ERROR_MSG,
901 self::LOGIN_ERROR);
904 $return = $this->database->loginToDB($user, $password);
906 if ($return == FALSE) {
907 throw new XML_RPC2_FaultException(
908 self::USERNAME_AND_PASSWORD_MISMATCH_MSG,
909 self::USERNAME_AND_PASSWORD_MISMATCH);
912 return $return;
916 * Get max image-size in bytes
918 * Returns max image-size
919 * @return int
921 function getMaxImageSize()
923 IrrecoLog::$server->log('XML-RPC getMaxImageSize');
924 $val = trim(ini_get('post_max_size'));
925 $last = strtolower($val[strlen($val)-1]);
927 switch($last) {
928 // The 'G' modifier is available since PHP 5.1.0
929 case 'g':
930 $val *= 1024;
931 case 'm':
932 $val *= 1024;
933 case 'k':
934 $val *= 1024;
937 $val = $val / 2 - (100 * 1024); //divided by 2 because of base64
939 IrrecoLog::$server->log("Max image-size: " . $val . "\n");
940 return $val;