Add move functionality master
authorJoey Schulze <joey@infodrom.org>
Sun, 27 Feb 2011 15:52:21 +0000 (16:52 +0100)
committerJoey Schulze <joey@infodrom.org>
Sun, 27 Feb 2011 15:52:21 +0000 (16:52 +0100)
This allows an incoming call to become a configured message that will
be played by vboxgetty when somebody calles (to be configured via
vbox.conf in /etc/isdn).

index.php
phone.css
phone.js
phone.php

index b8eecdd..2d003d7 100644 (file)
--- a/index.php
+++ b/index.php
@@ -17,6 +17,8 @@ if (!empty($_POST['func'])) {
     $data['call'] = $_POST['call'];
   } elseif ($_POST['func'] == 'save') {
     save_call();
+  } elseif ($_POST['func'] == 'move') {
+    move_call();
   } elseif ($_POST['func'] == 'messages') {
     $data['messages'] = read_directory('messages');
   }
@@ -93,6 +95,19 @@ Note<br><input id="edit_note" type="text" size="31"><br>
 </div>
 </div>
 
+<div class="editcall" id="container_move">
+<p class="title">Move message</p>
+<div style="padding-left: 5px;">
+<form id="move_form">
+<span id="move_details">&nbsp;</span><br>
+<input id="move_call" type="hidden">
+Filename<br><input id="move_fname" type="text" size="31"><br>
+Note<br><input id="move_note" type="text" size="31"><br>
+<input type="button" class="button" value="Move" onclick="move()" style="margin-top: 5px;">
+</form>
+</div>
+</div>
+
 <div class="editcall" id="container_config" style="display: none;">
 <p class="title">Configured messages</p>
 <ul class="phonelist" id="internal_calls">
index f922a02..4bfa2e7 100644 (file)
--- a/phone.css
+++ b/phone.css
@@ -115,6 +115,10 @@ div.editcall p {
     padding-left: 3px;
 }
 
+div.editcall#container_move {
+    top: 135px;
+}
+
 span#edit_status {
     padding-left: 5px;
 }
index 8400960..9f3a25e 100644 (file)
--- a/phone.js
+++ b/phone.js
@@ -1,7 +1,8 @@
 var menu_list = {
-    'title': 'Calls',
+    'title': 'Call',
     'items': [{'name': 'Archive', 'callback': menu_list_archive},
               {'name': 'Edit', 'callback': menu_list_edit},
+              {'name': 'Move', 'callback': menu_list_move},
               {'name': 'Delete', 'callback': menu_list_delete},
               {'name': 'Cancel', 'type': 'hide'}]
 };
@@ -14,6 +15,9 @@ function page_init()
     frame.src = '';
     fetch_incoming();
     fetch_archive();
+
+    var move = document.getElementById('container_move');
+    move.style.display = 'none';
 }
 
 function reload()
@@ -156,6 +160,24 @@ function save()
     ajax_request('save', params, save_callback);
 }
 
+function move_callback(data)
+{
+    var move = document.getElementById('container_move');
+    move.style.display = 'none';
+    fetch_incoming();
+}
+
+function move()
+{
+    var call = document.getElementById('move_call');
+    var fname = document.getElementById('move_fname');
+    var note = document.getElementById('move_note');
+    var params = 'call=' + call.value;
+    params += '&fname=' + fname.value + '&note=' + note.value;
+
+    ajax_request('move', params, move_callback);
+}
+
 function list_context(e)
 {
     var target = e.target;
@@ -228,6 +250,21 @@ function menu_list_edit(e)
     config.style.display = 'none';
 }
 
+function menu_list_move(e)
+{
+    var move = document.getElementById('container_move');
+    var details = document.getElementById('move_details');
+    var fname = document.getElementById('move_fname');
+    var call = document.getElementById('move_call');
+    move.style.display = '';
+    details.innerHTML = e.target.parentNode.payload['row'].innerHTML;
+    fname.value = e.target.parentNode.payload['call'];
+    call.value = e.target.parentNode.payload['call'];
+
+    e.target.parentNode.style.display = 'none';
+    e.target.parentNode.payload['row'].style.backgroundColor = '';
+}
+
 function menu_list_delete(e)
 {
     var params = 'dir='+e.target.parentNode.payload['dir']+'&call='+e.target.parentNode.payload['call'];
index ac8660c..7da22be 100644 (file)
--- a/phone.php
+++ b/phone.php
@@ -168,4 +168,25 @@ function save_call()
   write_info($_POST['dir'], $_POST['call'], $info);
 }
 
+function move_call()
+{
+  error_log(var_export($_POST,true));
+
+  $fname = str_replace(array('$',' ','/'),
+                      array('_','_','_'),
+                      $_POST['fname']);
+
+  $info = read_info('incoming', $_POST['call']);
+  $info['note'] = $_POST['note'];
+  write_info('incoming', $_POST['call'], $info);
+
+  error_log('fname -> ' . $fname);
+
+  $basename = SPOOL_DIR . '/incoming/' . $_POST['call'];
+  $newbase = SPOOL_DIR . '/messages/' . $fname;
+
+  rename($basename . '.vmsg', $newbase . '.msg');
+  rename($basename . '.info', $newbase . '.info');
+}
+
 ?>