Add Todoist installation script (need to be styled)

This commit is contained in:
Chouchen 2010-09-15 09:54:20 +00:00
parent 08469447cb
commit 9f637b565d
6 changed files with 42 additions and 35 deletions

View File

@ -1,21 +1,21 @@
<? <?
$xmla = simplexml_load_file('../db/todoist.xml'); $xmla = simplexml_load_file('../db/todoist.xml');
if(isset($_GET['token'])){ if(isset($_POST['token'])){
$token = trim($_GET['token']); $token = trim($_POST['token']);
$xmla->addChild("token", $token); $xmla->addChild("token", $token);
$xmla->asXML('../db/todoist.xml'); $xmla->asXML('../db/todoist.xml');
echo $token; echo "ok";
}else if(isset($_GET['name']) && isset($_GET['id'])){ }else if(isset($_POST['name']) && isset($_POST['id'])){
$name = trim($_GET['name']); $name = trim($_POST['name']);
$id = trim($_GET['id']); $id = trim($_POST['id']);
$xmla->addChild("name", $name); $xmla->addChild("name", $name);
$xmla->addChild("id", $id); $xmla->addChild("id", $id);
$xmla->asXML('../db/todoist.xml'); $xmla->asXML('../db/todoist.xml');
echo $id; echo "ok";
} }

View File

@ -1,10 +1,10 @@
<? <?
$xmla = simplexml_load_file('todoist.xml'); $xmla = simplexml_load_file('db/todoist.xml');
if($xmla->token== '' || $xmla->token == null) if($xmla->token== '' || $xmla->token == null)
header('Location: index.php'); header('Location: install-todoist.php');
if($xmla->name == '' || $xmla->name == null):?> if($xmla->name == '' || $xmla->name == null):?>
<html> <html>
<head> <head> <style> .selectableProject{text-decoration:underline; color:blue; cursor:pointer;} </style>
<title>Todoist : getProjects</title> <title>Todoist : getProjects</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/getProjectsList.php?token=<?=$xmla->token?>"></script> <script type="text/javascript" src="js/getProjectsList.php?token=<?=$xmla->token?>"></script>
@ -14,5 +14,5 @@ if($xmla->name == '' || $xmla->name == null):?>
</body> </body>
</html> </html>
<? else: <? else:
header('Location: getUncompletedTasks.php'); header('Location: index.php');
endif; endif;

View File

@ -150,13 +150,13 @@ if($config = simplexml_load_file('db/config.xml')){
<?}?> <?}?>
<?if($config_xml[6]->visibility == "true"){ <?if($config_xml[6]->visibility == "true"){
$xmla = simplexml_load_file('db/todoist.xml'); $xmla = simplexml_load_file('db/todoist.xml');
echo '<div id="todoList"></div>'; echo '<div id="todoList">';
if($xmla->token== '' || $xmla->token == null || $xmla->id == '' || $xmla->id == null) if($xmla->token== '' || $xmla->token == null || $xmla->id == '' || $xmla->id == null)
echo 'Impossible de trouver votre configuration. Merci de bien vouloir la recommencer.'; echo 'Impossible de trouver votre configuration. <a href="install-todoist.php">Cliquez ici</a> pour la mettre en place.</div>';
else{ else{
$token = $xmla->token; $token = $xmla->token;
$id = $xmla->id;?> $id = $xmla->id;?>
</div>
<script type="text/javascript" src="js/getUncompletedTasks.php?token=<?=$token?>&id=<?=$id?>"></script> <script type="text/javascript" src="js/getUncompletedTasks.php?token=<?=$token?>&id=<?=$id?>"></script>
<?}}?> <?}}?>
</body> </body>

24
install-todoist.php Normal file
View File

@ -0,0 +1,24 @@
<?
$xmla = simplexml_load_file('db/todoist.xml');
if($xmla->token == '' || $xmla->token == null):?>
<html>
<head>
<title>Todoist : Login</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body>
<fieldset>
<input type="text" name="email" id="email"/><br/>
<input type="password" name="password" id="password"/>
<span id="loginBtn">Cliquez ici pour vous identifier</span>
<div id="error"></div>
</fieldset>
</body>
</html>
<?
else:
header('Location: getProjectsList.php');
endif;

View File

@ -1,23 +1,6 @@
<?header('Content-type: application/javascript'); <?header('Content-type: application/javascript');
$token = $_GET['token']; $token = $_GET['token'];
?> ?>
function cbfunc(o){ function cbfunc(o){ $('body').append('<div id="results"><h2>Select your project</h2></div>'); $('#results').append('<ul id="uncompletedList"><ul>'); for(var i in o) { $('#uncompletedList').append('<li id="'+o[i].id+'" class="selectableProject">'+o[i].name+'</li>'); } }
var name = o[0].name; $(document).ready(function(){ var token = "<?=$token?>"; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://todoist.com/API/getProjects?token='+token+'&format=json&callback=cbfunc'; document.getElementsByTagName('head')[0].appendChild(script); $('.selectableProject').live('click', function(){ var name = $(this).text(); var id = $(this).attr('id'); $.post('ajax/saveTodoist.php', {name: name, id: id}, function(msg){ $('body').append('<a href="index.php">Etape suivante</a>'); if(msg=="ok"){ location.reload(); }else{ alert(msg); } }); });
var id = o[0].id;
if(id == undefined){
$('body').append('<span>ERROR</span>');
}else{
$.get('saveTodoist.php', {name: name, id: id}, function(){
window.location.reload();
});
}
}
$(document).ready(function(){
var token = "<?=$token?>";
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/getProjects?token='+token+'&format=json&callback=cbfunc';
document.getElementsByTagName('head')[0].appendChild(script);
}); });

View File

@ -3,8 +3,8 @@ function cbfunc(o){
if(token == undefined){ if(token == undefined){
$('#error').html('Identification erronnée'); $('#error').html('Identification erronnée');
}else{ }else{
$.get('saveTodoist.php', {token: token}, function(){ $.post('ajax/saveTodoist.php', {token: token}, function(data){ $('body').append('<a href="getProjectsList.php">Etape suivante</a>'); if(data=="ok"){
location.reload(true); location.reload(); }else{ alert(data); }
}); });
} }
} }