1+ <?php
2+ /* This Source Code Form is subject to the terms of the Mozilla Public
3+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+ // Render the header and sidebar
7+ require_once (realpath (__DIR__ . '/../includes/renderutils.php ' ));
8+ require_once (realpath (__DIR__ . '/../includes/functions.php ' ));
9+ require_once (realpath (__DIR__ . '/../includes/artificial_intelligence.php ' ));
10+ render_header_and_sidebar (['multiselect ' ], ['check_admin ' => true ]);
11+
12+ // Include the language file
13+ // Ignoring detections related to language files
14+ // @phan-suppress-next-line SecurityCheck-PathTraversal
15+ require_once (language_file ());
16+
17+ // If the extra directory exists
18+ if (is_dir (realpath (__DIR__ . '/../extras/artificial_intelligence ' )))
19+ {
20+ // Include the Artificial Intelligence Extra
21+ require_once (realpath (__DIR__ . '/../extras/artificial_intelligence/index.php ' ));
22+
23+ // If the user wants to activate the extra
24+ if (isset ($ _POST ['activate ' ]))
25+ {
26+ // Enable the Artificial Intelligence Extra
27+ enable_artificial_intelligence_extra ();
28+ }
29+
30+ // If the user wants to deactivate the extra
31+ if (isset ($ _POST ['deactivate ' ]))
32+ {
33+ // Disable the Artificial Intelligence Extra
34+ disable_artificial_intelligence_extra ();
35+ }
36+
37+ // If the user updated the configuration
38+ if (isset ($ _POST ['update_artificial_intelligence_settings ' ]))
39+ {
40+ // Update the artificial intelligence settings
41+ update_artificial_intelligence_settings ();
42+ }
43+ }
44+
45+ /*********************
46+ * FUNCTION: DISPLAY *
47+ *********************/
48+ function display ($ display = "" )
49+ {
50+ global $ lang ;
51+ global $ escaper ;
52+
53+ // If the extra directory exists
54+ if (is_dir (realpath (__DIR__ . '/../extras/artificial_intelligence ' )))
55+ {
56+ // But the extra is not activated
57+ if (!artificial_intelligence_extra ())
58+ {
59+ echo "<div class='card-body my-2 border'> " ;
60+ // If the extra is not restricted based on the install type
61+ if (!restricted_extra ("artificial_intelligence " ))
62+ {
63+ echo "
64+ <form id='activate_extra' name='activate' method='post' action=''>
65+ <input type='submit' value=' " . $ escaper ->escapeHtml ($ lang ['Activate ' ]) . "' name='activate' class='btn btn-submit'/>
66+ </form> " ;
67+ }
68+ // The extra is restricted
69+ else echo $ escaper ->escapeHtml ($ lang ['YouNeedToUpgradeYourSimpleRiskSubscription ' ]);
70+ echo "</div> " ;
71+ }
72+ // Once it has been activated
73+ else
74+ {
75+ // Include the Notification Extra
76+ require_once (realpath (__DIR__ . '/../extras/artificial_intelligence/index.php ' ));
77+
78+ display_artificial_intelligence ();
79+ }
80+ }
81+ // Otherwise, the Extra does not exist
82+ else
83+ {
84+ echo "
85+ <div class='card-body my-2 border'>
86+ <a href='https://www.simplerisk.com/extras' target='_blank' class='text-info'>Purchase the Extra</a>
87+ </div> " ;
88+ }
89+ }
90+ ?>
91+ <div class="row bg-white">
92+ <div class="col-12">
93+ <?php display (); ?>
94+
95+ <div class='card-body my-2 border'>
96+ <form name='anthropic_settings' method='post' action=''>
97+ <div class='row'>
98+ <div class='form-group'>
99+ <label>Anthropic API Key:</label>
100+ <?php display_anthropic_api_key_input () ?>
101+ </div>
102+ </div>
103+ </form>
104+ </div>
105+
106+ <?php
107+ // If we have an Anthropic API key
108+ if (get_setting ("anthropic_api_key " ) != false )
109+ {
110+ // Process the added/updated context
111+ $ parameter_array = get_artificial_intelligence_context_parameter_array ();
112+ $ settings_prefix = "ai_context_ " ;
113+ $ parameter_array = update_posted_settings_values ($ parameter_array , $ settings_prefix );
114+
115+ // If this was a POST to update the AI context
116+ if (isset ($ _POST ['save_ai_context ' ]))
117+ {
118+ // Update a setting for the last time this prefix was updated
119+ $ setting_name = $ settings_prefix . "last_saved " ;
120+ update_setting ($ setting_name , time ());
121+ }
122+
123+ // Provide the user with the ability to add context
124+ display_artificial_intelligence_add_context ($ parameter_array );
125+ }
126+ ?>
127+ </div>
128+ <script>
129+ <?php prevent_form_double_submit_script (['activate_extra ' , 'deactivate_extra ' ]); ?>
130+ </script>
131+ </div>
132+ <?php
133+ // Render the footer of the page. Please don't put code after this part.
134+ render_footer ();
135+ ?>
0 commit comments