Few tweaks to the plugins system
[PHPCredLocker.git] / views / Creds / add.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/** Add Credential
*
* Copyright (C) 2012 B Tasker
* Released under GNU GPL V2
* See LICENSE
*
*/ 
defined('_CREDLOCK') or die;
 
 
 
$creds = new CredDB;
global $notifications;
$notifications->setPageTitle("Add ". Lang::_('Credential'));
$plg = new Plugins;
 
if (BTMain::getVar('addCredSubmitted')){
 
  $cred = BTMain::getVar('frmCredential');
  $addr = BTMain::getVar('frmAddress');
  $user = BTMain::getVar('frmUser');
  
  if (!BTMain::getConnTypeSSL()){
            $crypt = new Crypto;
            $tlskey = BTMain::getsessVar('tls');
            $cred = $crypt->xordstring(base64_decode($cred),$tlskey);
            $addr = $crypt->xordstring(base64_decode($addr),$tlskey);
            $user = $crypt->xordstring(base64_decode($user),$tlskey);
         }
 
 
  $newcred = $creds->addCred(BTMain::getVar('cust'),BTMain::getVar('FrmCredType'),$cred,BTMain::getVar('frmClicky'),BTMain::getVar('frmGroup'),$addr,$user);
  // Add the cred to the db
  if ($newcred){
  // Success
  $notifications->setNotification("addCredSuccess");
 
     $data->cred->id = $newcred;
     $data->action = 'edit';
 
    
    echo $plg->loadPlugins("Creds",$data)->plgOutput;
 
 
  }else{
  $notifications->setNotification("addCredFail");
  }
 
 
 
 
 
}
 
$path = array(array('name'=>Lang::_("Credentials"),'url'=>'#'),array('name'=>'Add','url'=>'index.php?option=addCred&cust='.BTMain::getVar('cust')));
 
$notifications->setBreadcrumb($path);
 
$auth = new AuthDB;
$credtypes = $creds->getCredTypes();
$cust = BTMain::getVar('cust');
$custs = new CustDB;
$customers = $custs->getAllCustomers();
 
 
 
?>
 
<form method="POST" onsubmit="return checkNewCred();">
 
<input type="hidden" name="option" value="addCred">
<input type="hidden" name="addCredSubmitted" value="1">
<input type="hidden" name="frmClicky" id="frmClicky" value="0">
 
 
 
 
<label for='FrmCustomer'><?php echo Lang::_("Customer");?></label><select name="cust" id="FrmCustomer">
 
<?php
$crypt = new Crypto;
$crypt->safety = 0;
 
foreach ($customers as $customer){
 
$plaintext = $crypt->decrypt($customer->Name,'Customer');
 
$custdets[$plaintext] = "<option value='{$customer->id}'" ;
 
    if ($customer->id == $cust){
    $custdets[$plaintext] .= " selected";
    }
 
$custdets[$plaintext] .= ">$plaintext</option>";
 
}
 
ksort($cust);
echo implode("\n",$custdets);
?>
 
 
</select>
 
<label for='FrmCredType'><?php echo Lang::_("Credential Type");?></label><select id="FrmCredType" name="FrmCredType">
<?php 
      foreach ($credtypes as $cred){
 
      ?>
          <option value="<?php echo $cred->id;?>"><?php echo $crypt->decrypt($cred->Name,'CredType');?></option>
      <?php
 
      }
      unset($crypt);
  ?>
</select>
 
<label for="frmUser"><?php echo Lang::_("User");?></label><input type="text" name="frmUser" id="frmUser">
 
<label for="frmCredential"><?php echo Lang::_("Password");?></label><textarea id="frmCredential" name="frmCredential"></textarea>
<a href="javascript: genPwd('frmCredential',10);">Generate Password</a>
 
<label for="frmAddress"><?php echo Lang::_("Address");?></label><input type="text" name="frmAddress" id="frmAddress">
 
 
 
<?php include 'lib/includes/groupSelection.php'; ?>
 
 
<?php
 
    // Call any configured plugins
         
     $data->action = 'editfrmnew';
 
    
    echo $plg->loadPlugins("Creds",$data)->plgOutput;
 
 
?>
 
<input type="submit" class="btn btn-primary" value="Add <?php echo Lang::_("Credential");?>">
</form>