<?php
# ************** LICENCE ****************
/*
	Copyright (c) PORTANEO.
*/
# ***************************************
# portaneo mobile plugin install
#
# !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
# ***************************************
/*
 * name: Mobile portal v2
 * description: <div class='warning'>Portaneo mobile portal<br /><br />> To upload icons the 'mobile/images/icons/' directory must be writable</div>
 * dependencies: no
 * author: Cyril Kabache
 * url: http://www.portaneo.com
 */
register_hook('install_mobile/mobile','mobile_install');
register_hook('uninstall_mobile/mobile','mobile_uninstall');
register_hook('login_php','mobile_redirect',1,0);
register_hook('index_php','mobile_redirect',1,0);
register_admin_tab('Mobile','Mobile','mobile_admin_display');
register_hook('admin_header','loadAdminMobileJavascript',5,0);
register_hook('admin_frame_header','loadAdminMobileJavascript',5,0);
register_hook('admininterface_header','loadAdminMobileJavascript',5,0);

function mobile_install() {
	global $DB;
	$DB->sql = "SHOW TABLES LIKE 'mobile_'";
	$tables = $DB->select($DB->sql);
	if (empty($tables)) {
        $DB->sql = "CREATE TABLE `mobile_grantedusers` (`user_id` mediumint(8) NOT NULL,`access` int(1) NOT NULL,PRIMARY KEY  (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->execute($DB->sql);
        $DB->sql = "CREATE TABLE `mobile_selectedwidgets` ( `user_id` mediumint(10) unsigned NOT NULL, `profile_id` tinyint(3) unsigned NOT NULL default '0', `uniq` smallint(5) unsigned NOT NULL default '0', `nb_articles` mediumint(35) default '5', `item_id` mediumint(10) unsigned NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->execute($DB->sql);
        $DB->sql = "CREATE TABLE `mobile_userpref` (`user_id` mediumint(10) unsigned NOT NULL,`nb_portal` mediumint(10) unsigned NOT NULL default '5',`nb_reader` mediumint(10) unsigned NOT NULL default '10',`cb` mediumint(10) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
        $DB->execute($DB->sql);
        $DB->sql = "CREATE TABLE `mobile_widgets` (`item_id` mediumint(8) unsigned NOT NULL,`title` varchar(15) collate utf8_unicode_ci default NULL,`picture` varchar(250) collate utf8_unicode_ci NOT NULL,`available` int(1) unsigned NOT NULL,PRIMARY KEY  (`item_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";      
        $DB->execute($DB->sql);
        $DB->sql = "INSERT INTO `mobile_widgets` (`item_id`, `title`, `picture`, `available`) VALUES (84, 'Bloc-notes', 'mob_ico_15.png', 1), (85, 'Favoris', 'mob_ico_14.png', 1), (86, 'Lecteur RSS', 'mob_ico_1.png', 1), (112, 'Agenda', 'mob_ico_6.png', 1), (295, 'T&acirc;ches', 'mob_ico_30.png', 1), (401, 'Adresses', 'mob_ico_28.png', 1)";
        $DB->execute($DB->sql);
	}
	if (!copy('../includes/plugins/mobile/styles/mobile_css.css','../includes/plugins/mobile/styles/mobile_specif.css')) {echo "ERROR - CSS missing";}
}

function mobile_uninstall() {}

function mobile_redirect() {
	require_once('../includes/plugins/mobile/includes/detect_mobile.inc.php');
}

function mobile_admin_display() {
    echo "<div id='content' style='font-size:1em;margin: 0px;padding:5px;background: #fff;'></div>";
    ?><script>$p.mobile.initMenus();</script><?php
}

function loadAdminMobileJavascript() {
    echo "<script type='text/javascript' src='../includes/plugins/mobile/includes/mobile.js?v=1.0.0' ></script>";
    echo "<script type='text/javascript' src='../includes/plugins/mobile/l10n/".__LANG."/lang_mobile.js?v=1.0.0' ></script>";
    echo "<script type='text/javascript' src='../includes/php/admin-urls.js?v=1.0.0' ></script>";
    echo "<script type='text/javascript' src='../includes/plugins/mobile/includes/php/mobile-urls.js?v=1.0.0' ></script>";
}
?>